Should conversion operators be considered for function template argument deduction?

cig*_*ien 6 c++ templates language-lawyer template-argument-deduction

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
}
Run Code Online (Sandbox Code Playgroud)

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?

Dav*_*ing 4

GCC 在这里肯定是错误的:T&T&&[temp.deduct.type]/8 中的行不同,因此不兼容。为什么这样做尚不清楚。在另一个方向上犯错误会更有意义:如果参数被声明为S<T&&>并且参数的类型为S<int&>,那么至少会有一个Tint&)使得(由于引用崩溃)参数和参数类型是相同的。(说涉及通用引用也很容易犯错误。)