【发布时间】:2012-12-06 03:26:15
【问题描述】:
在涉及模板别名的替换失败的情况下(例如缺少成员类型名上的模板别名,如下面的代码 sn-p 中所示),是否应该触发错误?
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;
}
所以问题是:谁是正确的,为什么?
谢谢:-)
【问题讨论】:
-
clang -v说什么? Clang 3.3 trunk 编译代码就好了。 -
Debian clang 3.1-8 版本在这里,看来我只需要等待。感谢您的反馈!
-
你能不能去掉模板别名,只是为了简化一点
-
@Dave:问题的重点在于使用别名,所以...
-
@Xeo 哦,对不起。我只看了代码,还以为是关于 SFINAE 的。
标签: c++ c++11 sfinae template-aliases