summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/constant-expression.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-19 06:19:21 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-19 06:19:21 +0000
commitd0b4dd656d11d60855bf5b78c7059a3a6c5724d4 (patch)
tree35d257022b6b7e00a6cf5e0cc038a8a1c7b588ac /clang/test/SemaCXX/constant-expression.cpp
parentdec792ebb5de0a6b9ff7b9f5ae25682c7031e529 (diff)
downloadbcm5719-llvm-d0b4dd656d11d60855bf5b78c7059a3a6c5724d4.tar.gz
bcm5719-llvm-d0b4dd656d11d60855bf5b78c7059a3a6c5724d4.zip
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. llvm-svn: 146856
Diffstat (limited to 'clang/test/SemaCXX/constant-expression.cpp')
-rw-r--r--clang/test/SemaCXX/constant-expression.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/constant-expression.cpp b/clang/test/SemaCXX/constant-expression.cpp
index 0367cc55468..061e77591b1 100644
--- a/clang/test/SemaCXX/constant-expression.cpp
+++ b/clang/test/SemaCXX/constant-expression.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -pedantic %s
// C++ [expr.const]p1:
// In several places, C++ requires expressions that evaluate to an integral
// or enumeration constant: as array bounds, as case expressions, as
@@ -103,8 +103,17 @@ namespace IntOrEnum {
S<p> s; // expected-error {{not an integral constant expression}}
}
+extern const int recurse1;
+// recurse2 cannot be used in a constant expression because it is not
+// initialized by a constant expression. The same expression appearing later in
+// the TU would be a constant expression, but here it is not.
+const int recurse2 = recurse1;
+const int recurse1 = 1;
+int array1[recurse1]; // ok
+int array2[recurse2]; // expected-warning {{variable length array}} expected-warning {{integer constant expression}}
+
namespace FloatConvert {
typedef int a[(int)42.3];
typedef int a[(int)42.997];
- typedef int b[(int)4e10]; // expected-error {{variable length}}
+ typedef int b[(int)4e10]; // expected-warning {{variable length}} expected-error {{variable length}}
}
OpenPOWER on IntegriCloud