问题
struct X {
constexpr static char a1[] = "hello"; // Okay
constexpr static const char* a2[] = {"hello"}; // Error
};
int main(){}
Compiling with gcc gives the error:
error: a brace-enclosed initializer is not allowed here before '{' token
Is this an illegal use of constexpr?
EDIT
I tried 3 different versions of gcc, and it compiled on the newest 4.7.0 I have (I just downloaded it, I'm using mingw-w64), so it looks to be a fixed bug (a link to the bug would be nice though!).
4.7.0 20120311 (prerelease) // Okay
4.6.4 20120305 (prerelease) // Error
4.7.0 20110829 (experimental) // Error
回答1:
This is a bug which has been fixed. I have confirmed that the code compiles with g++ 4.7.0 20120311 (prerelease)
.
来源:https://stackoverflow.com/questions/9900242/error-with-constexprgcc-error-a-brace-enclosed-initializer-is-not-allowed-h