]> granicus.if.org Git - clang/commitdiff
Only do this for initializers of course.
authorAnders Carlsson <andersca@mac.com>
Sun, 16 Aug 2009 17:54:29 +0000 (17:54 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 16 Aug 2009 17:54:29 +0000 (17:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79197 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp

index ea534d3b2bd942ef101884c79a47475716c30bcf..1078bacde50c3447907df4cb0830ca64e6e27629 100644 (file)
@@ -93,15 +93,17 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
     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());
+    if (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());
+            CleanupScope scope(*this);
+            EmitCXXDestructorCall(Dtor, Dtor_Complete, Val.getAggregateAddr());
+          }
         }
       }
     }