[cfe-commits] r90460 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp lib/Sema/SemaType.cpp test/SemaTemplate/instantiate-static-var.cpp
Douglas Gregor
dgregor at apple.com
Thu Dec 3 09:10:38 PST 2009
Author: dgregor
Date: Thu Dec 3 11:10:37 2009
New Revision: 90460
URL: http://llvm.org/viewvc/llvm-project?rev=90460&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=90460&r1=90459&r2=90460&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Dec 3 11:10:37 2009
@@ -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;
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=90460&r1=90459&r2=90460&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Dec 3 11:10:37 2009
@@ -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);
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=90460&r1=90459&r2=90460&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Dec 3 11:10:37 2009
@@ -897,6 +897,9 @@
break;
}
+ if (T.isNull())
+ return T;
+
if (T == Context.UndeducedAutoTy) {
int Error = -1;
Modified: cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp?rev=90460&r1=90459&r2=90460&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp Thu Dec 3 11:10:37 2009
@@ -72,3 +72,23 @@
Z1<Y2<X2>::value> x2;
int y2[Y2<X2>::value];
}
+
+// PR5672
+template <int n>
+struct X3 {};
+
+class Y3 {
+ public:
+ ~Y3(); // The error isn't triggered without this dtor.
+
+ void Foo(X3<1>);
+};
+
+template <typename T>
+struct SizeOf {
+ static const int value = sizeof(T);
+};
+
+void MyTest3() {
+ Y3().Foo(X3<SizeOf<char>::value>());
+}
More information about the cfe-commits
mailing list