Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[temp.deduct.conv] Implementations think there is a defect in this subclause #5123

Open
xmh0511 opened this issue Nov 23, 2021 · 0 comments
Open

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Nov 23, 2021

#include <iostream>
struct C{
    template<typename Type>
    operator Type(){
        Type a{};
        return a;
    }
};

int main(){
    int const& rf = C{};
}

Consider the above example, the rules about deducing conversion function template arguments in defined as
[temp.deduct.conv] p1

Template argument deduction is done by comparing the return type of the conversion function template (call it P) with the type specified by the conversion-type-id of the conversion-function-id being looked up (call it A) as described in [temp.deduct.type]. If the conversion-function-id is constructed during overload resolution ([over.match.funcs]), the following transformations apply.

Implementations give the deduced A with the type int. However, according to [temp.deduct.conv] p1, [temp.deduct.conv] p2, [temp.deduct.conv] p3, and [temp.deduct.conv] p4, the deduced A should be int const. Since [temp.deduct.conv] p4 remove the top-level cv-qualifier prior to remove the reference. For this divergence, Clang's sources give the interpretation, which says

If A is a reference type, the type referred to by A is used for type deduction. We work around a defect in the standard here: cv-qualifiers are also removed from P and A in this case, unless P was a reference type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant