From e06274d5c5c6b2decc9f217a8913b28f846bfcfa Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 20 May 2009 21:51:01 +0000 Subject: [PATCH] Template instantiation for CXXExprWithTemporaries, which occurs when temporaries are generated for some object-constructing expressions in templates that are not type-dependent. Also, be sure to introduce the variable from a CXXConditionDeclExpr into the set of instantiated local variables. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72185 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateExpr.cpp | 14 +++++++++++++- test/SemaTemplate/instantiate-expr-4.cpp | 9 +++++++++ test/SemaTemplate/instantiate-function-1.cpp | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 1b2fa46957..099ce278f1 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -92,7 +92,7 @@ namespace { // FIXME: CXXDeleteExpr // FIXME: UnaryTypeTraitExpr // FIXME: QualifiedDeclRefExpr - // FIXME: CXXExprWithTemporaries + OwningExprResult VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); OwningExprResult VisitCXXUnresolvedConstructExpr( CXXUnresolvedConstructExpr *E); OwningExprResult VisitGNUNullExpr(GNUNullExpr *E); @@ -450,6 +450,7 @@ TemplateExprInstantiator::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E) { if (!Var) return SemaRef.ExprError(); + SemaRef.CurrentInstantiationScope->InstantiatedLocal(E->getVarDecl(), Var); return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr( E->getStartLoc(), SourceLocation(), @@ -877,6 +878,7 @@ TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) { return SemaRef.ExprError(); } + SemaRef.CurrentInstantiationScope->InstantiatedLocal(E->getVarDecl(), Var); return SemaRef.Owned(CXXConstructExpr::Create(SemaRef.Context, Var, T, E->getConstructor(), E->isElidable(), @@ -916,6 +918,16 @@ TemplateExprInstantiator::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { return SemaRef.Clone(E); } +Sema::OwningExprResult +TemplateExprInstantiator::VisitCXXExprWithTemporaries( + CXXExprWithTemporaries *E) { + OwningExprResult SubExpr = Visit(E->getSubExpr()); + if (SubExpr.isInvalid()) + return SemaRef.ExprError(); + + return SemaRef.ActOnFinishFullExpr(move(SubExpr)); +} + Sema::OwningExprResult TemplateExprInstantiator::VisitCXXUnresolvedConstructExpr( CXXUnresolvedConstructExpr *E) { diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index a5b55b35d7..8a3f7d858e 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -33,3 +33,12 @@ struct BuildTemporary0 { }; template struct BuildTemporary0<5, 7>; + +template +struct Temporaries0 { + void f() { + (void)X(N, M); + } +}; + +template struct Temporaries0<5, 7>; diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index caae97e60b..6182e1fe88 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -69,6 +69,9 @@ template struct X6 { return v; // expected-error{{incompatible type}} } + if (T x = t) { + t = x; + } return v; } }; -- 2.40.0