On Saturday, August 25, 2012 7:34 AM, Richard Smith wrote:
Could you give me some example code for your "nasty corner case", and I'll
fix my code. Thanks.
extern const int n;
constexpr int get() { return n; }
constexpr int n = get() + 1;
constexpr int m = get();
static_assert(m == n, "");
Wow, that is nasty and my first thought was: is that even legal?
This is the output from gcc 4.7.1:
~/testcase$ g++ -std=c++11 horrible.cpp
horrible.cpp: In function 'constexpr int get()':
horrible.cpp:2:33: error: the value of 'n' is not usable in a constant
expression
horrible.cpp:1:18: note: 'n' was not initialized with a constant expression
horrible.cpp: At global scope:
horrible.cpp:3:15: error: redeclaration 'n' differs in 'constexpr'
horrible.cpp:1:18: error: from previous declaration 'n'
horrible.cpp:4:23: error: 'constexpr int get()' called in a constant expression
What does the standard say? (I haven't got a copy myself.)
Cheers
Andy
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits