When we're building a CXXExprWithTemporaries, only include those
temporaries that are within our current evaluation context. That way,
nested evaluation contexts (e.g., within a sizeof() expression) won't
see temporaries from outer contexts. Also, make sure to push a new
evaluation context when instantiating the initializer of a variable;
this may be an unevaluated context or a potentially-evaluated context,
depending on whether it's an in-class initializer or not. Fixes PR5672.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90460 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 148dc63..44f7816 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -2069,14 +2069,17 @@
bool ShouldDestroyTemps) {
assert(SubExpr && "sub expression can't be null!");
- if (ExprTemporaries.empty())
+ unsigned FirstTemporary = ExprEvalContexts.back().NumTemporaries;
+ assert(ExprTemporaries.size() >= FirstTemporary);
+ if (ExprTemporaries.size() == FirstTemporary)
return SubExpr;
Expr *E = CXXExprWithTemporaries::Create(Context, SubExpr,
- &ExprTemporaries[0],
- ExprTemporaries.size(),
+ &ExprTemporaries[FirstTemporary],
+ ExprTemporaries.size() - FirstTemporary,
ShouldDestroyTemps);
- ExprTemporaries.clear();
+ ExprTemporaries.erase(ExprTemporaries.begin() + FirstTemporary,
+ ExprTemporaries.end());
return E;
}
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 95725bf..394f0ee 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -193,6 +193,11 @@
TSK_ImplicitInstantiation);
if (D->getInit()) {
+ if (Var->isStaticDataMember() && !D->isOutOfLine())
+ SemaRef.PushExpressionEvaluationContext(Sema::Unevaluated);
+ else
+ SemaRef.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
+
OwningExprResult Init
= SemaRef.SubstExpr(D->getInit(), TemplateArgs);
if (Init.isInvalid())
@@ -235,6 +240,7 @@
} else
SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init),
D->hasCXXDirectInitializer());
+ SemaRef.PopExpressionEvaluationContext();
} else if (!Var->isStaticDataMember() || Var->isOutOfLine())
SemaRef.ActOnUninitializedDecl(Sema::DeclPtrTy::make(Var), false);
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index afce5e3..526ab91 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -897,6 +897,9 @@
break;
}
+ if (T.isNull())
+ return T;
+
if (T == Context.UndeducedAutoTy) {
int Error = -1;