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
diff --git a/test/SemaCXX/constexpr-printing.cpp b/test/SemaCXX/constexpr-printing.cpp
index 341495c..726d177 100644
--- a/test/SemaCXX/constexpr-printing.cpp
+++ b/test/SemaCXX/constexpr-printing.cpp
@@ -1,18 +1,19 @@
// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify
-constexpr int extract(struct S &s);
+struct S;
+constexpr int extract(const S &s);
struct S {
- constexpr S() : n(extract(*this)), m(0) {}
+ constexpr S() : n(extract(*this)), m(0) {} // expected-note {{in call to 'extract(s1)'}}
constexpr S(int k) : n(k), m(extract(*this)) {}
int n, m;
};
-constexpr int extract(S &s) { return s.n; }
+constexpr int extract(const S &s) { return s.n; } // expected-note {{subexpression}}
// FIXME: once we produce notes for constexpr variable declarations, this should
// produce a note indicating that S.n is used uninitialized.
-constexpr S s1; // expected-error {{constant expression}}
+constexpr S s1; // expected-error {{constant expression}} expected-note {{in call to 'S()'}}
constexpr S s2(10);
typedef __attribute__((vector_size(16))) int vector_int;