Handle destruction of temporaries used in default argument

construction of constructor calls.

llvm-svn: 78222
This commit is contained in:
Fariborz Jahanian 2009-08-05 18:17:32 +00:00
parent 4b5c761af2
commit d460cb4356
3 changed files with 14 additions and 2 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}