一位朋友正在用clang ++编译一些代码;我用g ++失败了。在这两种情况下,我们都使用-std=c++11
。
我将其提炼为以下示例:
enum A { A_foo = 23 };
class FooBar {
// This works in both:
int e1 = first<A_foo, int>();
int e2 = third<int, (int) A_foo>();
// Only works in clang:
//int e3 = second<int, A_foo>();
//int e4 = third<int, A_foo>();
template <A val, class U> int first() { return val; }
template <class U, A val> int second() { return val; }
template <class U, int val> int third() { return val; }
};
int main() {
FooBar bar;
}
此代码在clang ++中编译{{1}}的所有初始化。另一方面,g ++不会编译已注释掉的行,即使eN
和first
仅因其模板参数的顺序而不同。
关于解释的任何想法?