Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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?

like image 546
Dalibor Frivaldsky Avatar asked Oct 01 '22 12:10

Dalibor Frivaldsky


1 Answers

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 [...]

like image 104
ecatmur Avatar answered Oct 11 '22 19:10

ecatmur