Error with constexpr(gcc) - error: a brace-enclosed initializer is not allowed here before '{' token

寵の児 提交于 2019-12-23 09:58:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!