Error when a constexpr (gcc) error occurs: an initializer enclosed in curly braces is not allowed here before the '{' character

struct X { constexpr static char a1[] = "hello"; // Okay constexpr static const char* a2[] = {"hello"}; // Error }; int main(){} 

Compiling with gcc gives an error:

error: initializer enclosed in curly braces is not allowed here before the '{' token

Is it illegal to use constexpr?

EDIT

I tried 3 different versions of gcc and compiled them on the latest 4.7.0 (I just downloaded it, I use mingw-w64), so it looks like a fixed error (a link to the error would be nice!).

4.7.0 20120311 (preerelease) // Good 4.6.4 20120305 (pre-transmission) // Error
4.7.0 20110829 (experimental) // Error

+6
source share
1 answer

This is a bug fixed. I have confirmed that the code compiles with g++ 4.7.0 20120311 (prerelease) .

+2
source

Source: https://habr.com/ru/post/911826/


All Articles