简体   繁体   English

“ abc” [0]不是编译时常量

[英]“abc”[0] not a compile-time constant

I have this code: 我有以下代码:

template< char... chars >
struct VariadicTemplate
{};


int
main()
{
    VariadicTemplate< "abc"[ 0 ], "abc"[ 1 ], "abc"[ 2 ] >  v;
}

This compiles fine with mingw-w64 4.8.1 . 这可以使用mingw-w64 4.8.1进行编译。 However, the same does not compile under MSVC 2013 nor the VC++ November CTP with an error: 但是,在MSVC 2013或VC ++ November CTP下不会编译相同的错误:

Error 1 error C2975: 'chars' : invalid template argument for 'VariadicTamplate', expected compile-time constant expression 错误1错误C2975:“字符”:“ VariadicTamplate”的模板参数无效,预期的编译时常量表达式

Which of the "no"s or "partial"s refer to this? 哪个“否”或“部分”指的是这个? 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 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

If none, is this a compiler bug? 如果没有,这是编译器错误吗?

This change in behavior from C++03 to C++11 can be located in 5.19 Constant expressions (same clause both standards). 从C ++ 03到C ++ 11的这种行为变化可以在5.19常量表达式中找到 (两个标准都相同)。 As such, I suspect it would be covered by the constexpr no/partial. 因此,我怀疑它会被constexpr no / partial覆盖。

Note that the paper given as reference for the constexpr feature, n2235 , is where the change to 5.19 was introduced: 请注意,作为constexpr功能n2235的参考的论文是引入对5.19的更改的地方:

4.5.3 Constant expressions revised 4.5.3修改常量表达式

Paragraph modification. 修改段落。 Replace section 5.19 with [...] 用[...]替换第5.19节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM