template<bool b = 2> void foo(void) {}
template void foo();
template<unsigned char n = 258> void bar(void) {}
template void bar();
Run Code Online (Sandbox Code Playgroud)
GCC实例化foo <true>和bar <2>; Clang拒绝两个"错误:非类型模板参数求值为2,不能缩小到'bool'类型[-Wc ++ 11-narrowing]".
以上代码有效吗?这是其中一个的错误吗?
使用的版本:Clang 3.8.0-2ubuntu4,GCC 5.4.0 20160609(Ubuntu 5.4.0-6ubuntu1~16.04.2)