]> granicus.if.org Git - clang/commitdiff
Handle destruction of temporaries used in default argument
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Aug 2009 18:17:32 +0000 (18:17 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Aug 2009 18:17:32 +0000 (18:17 +0000)
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
lib/Sema/SemaInit.cpp
test/CodeGenCXX/default-arg-temps.cpp

index 8c1b880b86912664099e197a77e2a3909e189c9a..106c754d7565d6e5846f49afe47163bf4b4f4647 100644 (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);
 }
 
index a92f7f4a5341c4a76dc49d941e54e5b29020c73a..445cd691d6ad771d7d7b2c25b7b0a601ad832618 100644 (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;
       }
       
index 2dcf773346a87516add29e4523be05669d23939d..2651446669b8a951b4bf10182e8aa7d603588f67 100644 (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;
 }