From: Richard Smith Date: Thu, 30 May 2013 22:40:16 +0000 (+0000) Subject: Walk over MaterializeTemporaryExpr when reverting an initializer to its X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=858c2c317e7f176df72c4507a91eeddcfc5316fd;p=clang Walk over MaterializeTemporaryExpr when reverting an initializer to its syntactic form in template instantiation. Previously, this blocked the reversion and we ended up losing inner CXXBindTemporaryExprs (and thus forgetting to call destructors!). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182969 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 7f3a7d7540..4ebcfa292f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2630,6 +2630,9 @@ ExprResult TreeTransform::TransformInitializer(Expr *Init, if (ExprWithCleanups *ExprTemp = dyn_cast(Init)) Init = ExprTemp->getSubExpr(); + if (MaterializeTemporaryExpr *MTE = dyn_cast(Init)) + Init = MTE->GetTemporaryExpr(); + while (CXXBindTemporaryExpr *Binder = dyn_cast(Init)) Init = Binder->getSubExpr(); diff --git a/test/CodeGenCXX/cxx0x-initializer-constructors.cpp b/test/CodeGenCXX/cxx0x-initializer-constructors.cpp index be5b44df1f..efbf318b81 100644 --- a/test/CodeGenCXX/cxx0x-initializer-constructors.cpp +++ b/test/CodeGenCXX/cxx0x-initializer-constructors.cpp @@ -35,3 +35,19 @@ void fn4() { // CHECK: call void @_ZN1SC1Eidd(%struct.S* %{{.+}}, i32 1, double 2.000000e+00, double 3.000000e+00) // CHECK: call void @_ZN1SC1Eidd(%struct.S* %{{.+}}, i32 4, double 5.000000e+00, double 6.000000e+00) } + +namespace TreeTransformBracedInit { + struct S {}; + struct T { T(const S &); T(const T&); ~T(); }; + void x(const T &); + template void foo(const S &s) { + // Instantiation of this expression used to lose the CXXBindTemporaryExpr + // node and thus not destroy the temporary. + x({s}); + } + template void foo(const S&); + // CHECK: define {{.*}} void @_ZN23TreeTransformBracedInit3fooIvEEvRKNS_1SE( + // CHECK: call void @_ZN23TreeTransformBracedInit1TC1ERKNS_1SE( + // CHECK-NEXT: call void @_ZN23TreeTransformBracedInit1xERKNS_1TE( + // CHECK-NEXT: call void @_ZN23TreeTransformBracedInit1TD1Ev( +}