小编Alc*_*aro的帖子

超出范围模板参数的预期行为?

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)

c++ templates

5
推荐指数
1
解决办法
94
查看次数

标签 统计

c++ ×1

templates ×1