]> granicus.if.org Git - clang/commitdiff
Destroy bound temporaries.
authorAnders Carlsson <andersca@mac.com>
Sun, 16 Aug 2009 17:50:25 +0000 (17:50 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 16 Aug 2009 17:50:25 +0000 (17:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79196 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
lib/CodeGen/CGExpr.cpp

index 0f1354754b3c0b4ac9fe1b7490e60ca9c38bb8ce..c2efcd228f94696efc7574f84728d0ae5542a89e 100644 (file)
@@ -486,7 +486,6 @@ class CXXConstructExpr : public Expr {
   
   Stmt **Args;
   unsigned NumArgs;
-
   
 protected:
   CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 
index 3818f56df9413a210358d3c5c0da710cf9830835..ea534d3b2bd942ef101884c79a47475716c30bcf 100644 (file)
@@ -87,8 +87,24 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
       return RValue::get(LV.getAddress());
     Val = EmitLoadOfLValue(LV, E->getType());
   } else {
+    // FIXME: Initializers don't work with casts yet. For example
+    // const A& a = B();
+    // if B inherits from A.
     Val = EmitAnyExprToTemp(E, /*IsAggLocVolatile=*/false,
                             IsInitializer);
+    
+    // We might have to destroy the temporary variable.
+    if (const RecordType *RT = E->getType()->getAs<RecordType>()) {
+      if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+        if (!ClassDecl->hasTrivialDestructor()) {
+          const CXXDestructorDecl *Dtor = 
+            ClassDecl->getDestructor(getContext());
+          
+          CleanupScope scope(*this);
+          EmitCXXDestructorCall(Dtor, Dtor_Complete, Val.getAggregateAddr());
+        }
+      }
+    }
   }
 
   if (Val.isAggregate()) {