diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-19 06:19:21 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-19 06:19:21 +0000 |
commit | 099e7f647ccda915513f2b2ec53352dc756082d3 (patch) | |
tree | 20a7796c73f49f5e39604681e185a62bb9027f00 /test/CXX/expr/expr.const/p2-0x.cpp | |
parent | 925be547b163675b312e3cac0cc7f37f31d787c1 (diff) |
constexpr handling improvements. Produce detailed diagnostics when a 'constexpr'
variable is initialized by a non-constant expression, and pass in the variable
being declared so that earlier-initialized fields' values can be used.
Rearrange VarDecl init evaluation to make this possible, and in so doing fix a
long-standing issue in our C++ constant expression handling, where we would
mishandle cases like:
extern const int a;
const int n = a;
const int a = 5;
int arr[n];
Here, n is not initialized by a constant expression, so can't be used in an ICE,
even though the initialization expression would be an ICE if it appeared later
in the TU. This requires computing whether the initializer is an ICE eagerly,
and saving that information in PCH files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146856 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/expr/expr.const/p2-0x.cpp')
-rw-r--r-- | test/CXX/expr/expr.const/p2-0x.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/test/CXX/expr/expr.const/p2-0x.cpp b/test/CXX/expr/expr.const/p2-0x.cpp index d02db92a26..aa83fc7fa9 100644 --- a/test/CXX/expr/expr.const/p2-0x.cpp +++ b/test/CXX/expr/expr.const/p2-0x.cpp @@ -78,13 +78,13 @@ namespace NonConstExprReturn { namespace NonConstExprCtor { struct T { constexpr T(const int &r) : - r(r) { // expected-note {{reference to temporary cannot be used to initialize a member in a constant expression}} + r(r) { // expected-note 2{{reference to temporary cannot be used to initialize a member in a constant expression}} } const int &r; }; constexpr int n = 0; constexpr T t1(n); // ok - constexpr T t2(0); // expected-error {{must be initialized by a constant expression}} + constexpr T t2(0); // expected-error {{must be initialized by a constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'T(0)'}} struct S { int n : T(4).r; // expected-error {{constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'T(4)'}} @@ -187,8 +187,8 @@ namespace References { constexpr int e = 42; int &f = const_cast<int&>(e); extern int &g; - constexpr int &h(); // expected-note {{here}} - int &i = h(); + constexpr int &h(); // expected-note 2{{here}} + int &i = h(); // expected-note {{here}} expected-note {{undefined function 'h' cannot be used in a constant expression}} constexpr int &j() { return b; } int &k = j(); @@ -202,7 +202,7 @@ namespace References { int F : f - 11; int G : g; // expected-error {{constant expression}} int H : h(); // expected-error {{constant expression}} expected-note {{undefined function 'h'}} - int I : i; // expected-error {{constant expression}} + int I : i; // expected-error {{constant expression}} expected-note {{initializer of 'i' is not a constant expression}} int J : j(); int K : k; }; |