我有这个代码:
template< char... chars >
struct VariadicTemplate
{};
int
main()
{
VariadicTemplate< "abc"[ 0 ], "abc"[ 1 ], "abc"[ 2 ] > v;
}
这与 mingw-w64 4.8.1 编译良好。但是,在 MSVC 2013 和 VC++ November CTP 下都无法编译并出现错误:
Error 1 error C2975: 'chars' : invalid template argument for 'VariadicTamplate', expected compile-time constant expression
哪个“否”或“部分”指的是这个? http://blogs.msdn.com/b/vcblog/archive/2013/12/02/c-11-14-core-language-features-in-vs-2013-and-the-nov-2013-ctp.aspx
如果没有,这是编译器错误吗?
最佳答案
这种从 C++03 到 C++11 的行为变化可以在 5.19 常量表达式 中找到(两个标准的子句相同)。因此,我怀疑它会被 constexpr no/partial 涵盖。
请注意,作为 constexpr 功能引用的论文 n2235 , 是引入 5.19 更改的地方:
4.5.3 Constant expressions revised
Paragraph modification. Replace section 5.19 with [...]
关于c++ - "abc"[0] 不是编译时常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21989684/