From caa499b50bd6d423d095b79aca857f1c57345a0a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 5 Aug 2009 18:17:32 +0000 Subject: [PATCH] Handle destruction of temporaries used in default argument construction of constructor calls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78222 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 1 + lib/Sema/SemaInit.cpp | 1 + test/CodeGenCXX/default-arg-temps.cpp | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8c1b880b86..106c754d75 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2396,6 +2396,7 @@ void Sema::InitializeVarWithConstructor(VarDecl *VD, DeclInitType, Constructor, false, Exprs, NumExprs); MarkDeclarationReferenced(VD->getLocation(), Constructor); + Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true); VD->setInit(Context, Temp); } diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index a92f7f4a53..445cd691d6 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -179,6 +179,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, Init = BuildCXXConstructExpr(Context, DeclType, Constructor, false, &Init, 1); + Init = MaybeCreateCXXExprWithTemporaries(Init, /*DestroyTemps=*/true); return false; } diff --git a/test/CodeGenCXX/default-arg-temps.cpp b/test/CodeGenCXX/default-arg-temps.cpp index 2dcf773346..2651446669 100644 --- a/test/CodeGenCXX/default-arg-temps.cpp +++ b/test/CodeGenCXX/default-arg-temps.cpp @@ -7,9 +7,19 @@ struct T { void f(const T& t = T()); +class X { // ... +public: + X(); + X(const X&, const T& t = T()); +}; + void g() { - // RUN: grep "call void @_ZN1TC1Ev" %t | count 2 && - // RUN: grep "call void @_ZN1TD1Ev" %t | count 2 + // RUN: grep "call void @_ZN1TC1Ev" %t | count 4 && + // RUN: grep "call void @_ZN1TD1Ev" %t | count 4 f(); f(); + + X a; + X b(a); + X c = a; } -- 2.40.0