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/SemaCXX/constexpr-depth.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/SemaCXX/constexpr-depth.cpp')
-rw-r--r-- | test/SemaCXX/constexpr-depth.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/SemaCXX/constexpr-depth.cpp b/test/SemaCXX/constexpr-depth.cpp index b8ae6682c5..feba6fde3f 100644 --- a/test/SemaCXX/constexpr-depth.cpp +++ b/test/SemaCXX/constexpr-depth.cpp @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -DMAX=128 -fconstexpr-depth 128 -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -DMAX=1 -fconstexpr-depth 1 +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -DMAX=2 -fconstexpr-depth 2 // RUN: %clang -std=c++11 -fsyntax-only -Xclang -verify %s -DMAX=10 -fconstexpr-depth=10 -constexpr int depth(int n) { return n > 1 ? depth(n-1) : 0; } +constexpr int depth(int n) { return n > 1 ? depth(n-1) : 0; } // expected-note {{exceeded maximum depth}} expected-note +{{}} -constexpr int kBad = depth(MAX + 1); // expected-error {{must be initialized by a constant expression}} +constexpr int kBad = depth(MAX + 1); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'depth(}} constexpr int kGood = depth(MAX); |