When a static storage duration temporary appears in a constant expression, it
must be initialized by a constant expression (not just a core constant
expression), because we're going to emit it as a global. Core issue for this is
pending.
llvm-svn: 183388
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 19eaf55..d94efc1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4099,12 +4099,17 @@
Result.set(E, Info.CurrentCall->Index);
}
+ QualType Type = Inner->getType();
+
// Materialize the temporary itself.
- if (!EvaluateInPlace(*Value, Info, Result, Inner))
+ if (!EvaluateInPlace(*Value, Info, Result, Inner) ||
+ (E->getStorageDuration() == SD_Static &&
+ !CheckConstantExpression(Info, E->getExprLoc(), Type, *Value))) {
+ *Value = APValue();
return false;
+ }
// Adjust our lvalue to refer to the desired subobject.
- QualType Type = Inner->getType();
for (unsigned I = Adjustments.size(); I != 0; /**/) {
--I;
switch (Adjustments[I].Kind) {