]> granicus.if.org Git - clang/commitdiff
If a member variable of reference type is bound to a temporary in its member initiali...
authorAnders Carlsson <andersca@mac.com>
Fri, 6 Nov 2009 04:19:02 +0000 (04:19 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 6 Nov 2009 04:19:02 +0000 (04:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86230 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
test/CodeGenCXX/temporaries.cpp

index 281aa604fe3a7222f41cff4ff1ece81c8719aca5..9cd44fda95482c3d296f0c65c3e46b2ce939fb51 100644 (file)
@@ -264,6 +264,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD,
     if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
       EmitCtorPrologue(CD, GD.getCtorType());
       EmitStmt(S);
+      
+      // If any of the member initializers are temporaries bound to references
+      // make sure to emit their destructors.
+      EmitCleanupBlocks(0);
+      
     } else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD)) {
       llvm::BasicBlock *DtorEpilogue  = createBasicBlock("dtor.epilogue");
       PushCleanupBlock(DtorEpilogue);
index 5366612001aa3a74553eb0398273bf452084b95d..87ca9ca7d421425331db7b7eb0ca0ff8af34c644 100644 (file)
@@ -131,6 +131,7 @@ struct B {
   int a1;
   int a2;
   B();
+  ~B();
 };
 
 B::B()
@@ -147,4 +148,20 @@ B::B()
   f();
 }
   
+struct C {
+  C();
+  
+  const B& b;
+};
+
+C::C() 
+  // CHECK: call void @_ZN6PR50771BC1Ev
+  : b(B()) {
+  // CHECK: call void @_ZN6PR50771fEv
+  f();
+  
+  // CHECK: call void @_ZN6PR50771BD1Ev
+}
+
+
 }