]> granicus.if.org Git - clang/commitdiff
If the element type of an initializer list has a destructor, make sure we check it...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 5 Mar 2012 19:35:43 +0000 (19:35 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 5 Mar 2012 19:35:43 +0000 (19:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152048 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaInit.cpp
test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

index 1893d6dfa1069887532f4230ccca3af251a02f9e..f6662ba37fe3269166c8990a80c01007435ab430 100644 (file)
@@ -641,8 +641,7 @@ ExprResult Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
   if (RD->hasIrrelevantDestructor())
     return Owned(E);
 
-  CXXDestructorDecl *Destructor
-    = const_cast<CXXDestructorDecl*>(LookupDestructor(RD));
+  CXXDestructorDecl *Destructor = LookupDestructor(RD);
   if (!Destructor)
     return Owned(E);
 
index ba4453c08c4d973a67fc2e41fd32f0a29a748b0d..5d2536ae1b6bedb887345b32234d57c36768e6c0 100644 (file)
@@ -5309,6 +5309,19 @@ InitializationSequence::Perform(Sema &S,
       bool Success = S.isStdInitializerList(Dest, &E);
       (void)Success;
       assert(Success && "Destination type changed?");
+
+      // If the element type has a destructor, check it.
+      if (CXXRecordDecl *RD = E->getAsCXXRecordDecl()) {
+        if (!RD->hasIrrelevantDestructor()) {
+          if (CXXDestructorDecl *Destructor = S.LookupDestructor(RD)) {
+            S.MarkFunctionReferenced(Kind.getLocation(), Destructor);
+            S.CheckDestructorAccess(Kind.getLocation(), Destructor,
+                                    S.PDiag(diag::err_access_dtor_temp) << E);
+            S.DiagnoseUseOfDecl(Destructor, Kind.getLocation());
+          }
+        }
+      }
+
       InitListExpr *ILE = cast<InitListExpr>(CurInit.take());
       unsigned NumInits = ILE->getNumInits();
       SmallVector<Expr*, 16> Converted(NumInits);
index 775060bfac2b94c5f9a69208d7c1ca4f53ef10dc..81ce559844665c6c40cb1c2bf9beaf38c2c79754 100644 (file)
@@ -232,3 +232,21 @@ void fn11() {
   destroyme2 dm2;
   // CHECK: call void @_ZN10destroyme2D1Ev
 }
+
+namespace PR12178 {
+  struct string {
+    string(int);
+    ~string();
+  };
+
+  struct pair {
+    string a;
+    int b;
+  };
+
+  struct map {
+    map(std::initializer_list<pair>);
+  };
+
+  map m{ {1, 2}, {3, 4} };
+}