}
} else {
// FIXME: Allow folding of values of any literal type in all languages.
- if (Info.getLangOpts().CPlusPlus11) {
+ if (Info.checkingPotentialConstantExpression() &&
+ VD->getType().isConstQualified() && !VD->hasDefinition(Info.Ctx)) {
+ // The definition of this variable could be constexpr. We can't
+ // access it right now, but may be able to in future.
+ } else if (Info.getLangOpts().CPlusPlus11) {
Info.Diag(E, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
Info.Note(VD->getLocation(), diag::note_declared_at);
} else {
}
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
- Result = APValue(APValue::UninitStruct(), CXXRD ? CXXRD->getNumBases() : 0,
- std::distance(RD->field_begin(), RD->field_end()));
+ if (Result.isUninit())
+ Result = APValue(APValue::UninitStruct(), CXXRD ? CXXRD->getNumBases() : 0,
+ std::distance(RD->field_begin(), RD->field_end()));
unsigned ElementNo = 0;
bool Success = true;
constexpr int j = 0;
constexpr int k; // expected-error {{default initialization of an object of const type}}
}
+
+ extern const int q;
+ constexpr int g() { return q; }
+ constexpr int q = g();
+ static_assert(q == 0, "zero-initialization should precede static initialization");
+
+ extern int r; // expected-note {{here}}
+ constexpr int h() { return r; } // expected-error {{never produces a constant}} expected-note {{read of non-const}}
+
+ struct S { int n; };
+ extern const S s;
+ constexpr int x() { return s.n; }
+ constexpr S s = {x()};
+ static_assert(s.n == 0, "zero-initialization should precede static initialization");
}
namespace ComplexConstexpr {