#StackBounty: #c++ #templates #language-lawyer #template-argument-deduction Should conversion operators be considered for function temp…

Bounty: 50

Consider the following code:

template<typename>
struct S 
{
    operator S<int&>();  
};

template<typename T>
void f(S<T&>);

int main() 
{
    f(S<int&&>{});  // gcc ok
                    // clang error
}

gcc uses the conversion operator on the temporary argument, returning S<int&> which is matched by S<T&>, and accepts the call.

clang doesn’t consider the conversion operator, fails to match T& against int&&, and rejects the call.

So what does the language say should happen here?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.