如果替换失败涉及模板别名(例如,缺少的成员类型名称上的模板别名,如下面的代码片段中所示),是否应触发错误?
Clang和gcc似乎对此持不同意见:
// some types
struct bar { };
struct foo {
typedef void member_type;
};
// template alias
template<class T>
using member = typename T::member_type;
template<class T>
void baz(... ) { }
// only works for gcc, clang fails with: no type named 'member_type'
// in 'bar'
template<class T>
void baz( member<T>* ) { }
int main(int, char** ) {
baz<bar>(0); // picks first
baz<foo>(0); // picks second
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以问题是:谁是正确的,为什么?
谢谢 :-)