6
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

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
  • @BenjaminLindley: I downloaded a newer version and it worked, so it seems to be a fixed bug (see my edits). Thanks! (Should I delete this question??) – Jesse Good Mar 28 '12 at 02:36
  • 1
    @Jesse: I would rather leave the question here (though improve on the title if possible, for example adding the error message). This way the next person having this issue will know to update. – Matthieu M. Mar 28 '12 at 06:45

1 Answers1

2

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

Jesse Good
  • 50,901
  • 14
  • 124
  • 166