简体   繁体   中英

“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 . However, the same does not compile under MSVC 2013 nor the VC++ November CTP with an error:

Error 1 error C2975: 'chars' : invalid template argument for 'VariadicTamplate', expected compile-time constant expression

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

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). As such, I suspect it would be covered by the constexpr no/partial.

Note that the paper given as reference for the constexpr feature, n2235 , is where the change to 5.19 was introduced:

4.5.3 Constant expressions revised

Paragraph modification. Replace section 5.19 with [...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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