[cfe-commits] [Patch 4 of 5] Proposed fix for PR12850
Andy Gibbs
andyg1001 at hotmail.co.uk
Sat Aug 25 02:25:39 PDT 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120825/0439f696/attachment.html>
More information about the cfe-commits
mailing list