re PR c++/49605 (-Wdelete-non-virtual-dtor is not picky enough)
authorJonathan Wakely <jwakely.gcc@gmail.com>
Fri, 1 Jul 2011 22:24:42 +0000 (22:24 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 1 Jul 2011 22:24:42 +0000 (23:24 +0100)
2011-07-01  Jonathan Wakely  <jwakely.gcc@gmail.com>

PR c++/49605
* init.c (build_delete): Only warn for sfk_deleting_destructor.

From-SVN: r175771

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/delete-non-virtual-dtor.C

index 81252992e3695b5c7d00c51800b9e44a7ae6286b..6ffebf1b0fea402e74902e066cbd893796114b1f 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-01  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       PR c++/49605
+       * init.c (build_delete): Only warn for sfk_deleting_destructor.
+
 2011-07-01  Jakub Jelinek  <jakub@redhat.com>
 
        * Make-lang.in (cp/decl.o): Depend on pointer-set.h.
index f80c475f7ac2bbbacc9d56921f826a6d4f2598b2..7970b9ac476099bb80d5809117c3e15de3eb117c 100644 (file)
@@ -3467,8 +3467,9 @@ build_delete (tree type, tree addr, special_function_kind auto_delete,
                }
              complete_p = false;
            }
-         else if (warn_delnonvdtor && MAYBE_CLASS_TYPE_P (type)
-                  && !CLASSTYPE_FINAL (type) && TYPE_POLYMORPHIC_P (type))
+         else if (auto_delete == sfk_deleting_destructor && warn_delnonvdtor
+                  && MAYBE_CLASS_TYPE_P (type) && !CLASSTYPE_FINAL (type)
+                  && TYPE_POLYMORPHIC_P (type))
            {
              tree dtor;
              dtor = CLASSTYPE_DESTRUCTORS (type);
index c13fd9f5da3f690dfedf8185ea8b5bdfbeb49c56..5d44545dd845b3e9b01924ec5715bcc0b07bd9e7 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-01  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       PR c++/49605
+       * g++.dg/warn/delete-non-virtual-dtor.C: Adjust.
+
 2011-07-01  Jason Merrill  <jason@redhat.com>
 
        PR c++/48261
index 9849b1edfa8e662238685c6cc51b9a635d9705f8..c4acbde26a1cd07a740216988b19163d1bd038d2 100644 (file)
@@ -5,6 +5,7 @@ struct polyBase { virtual void f(); };
 
 void f(polyBase* p, polyBase* arr)
 {
+  polyBase pb;
   delete p;      // { dg-warning "non-virtual destructor might" }
   delete [] arr;
 }
@@ -13,6 +14,7 @@ struct polyDerived : polyBase { };
 
 void f(polyDerived* p, polyDerived* arr)
 {
+  polyDerived pd;
   delete p;      // { dg-warning "non-virtual destructor might" }
   delete [] arr;
 }
@@ -29,6 +31,7 @@ struct finalDerived final : polyBase { };
 
 void f(finalDerived* p, finalDerived* arr)
 {
+  finalDerived fd;
   delete p;      // no error for final classes
   delete [] arr;
 }
@@ -38,7 +41,26 @@ struct safeDerived : safeBase { virtual void f(); };
 
 void f(safeDerived* p, safeDerived* arr)
 {
+  safeDerived sd;
   delete p;      // no error because base has virtual dtor
   delete [] arr;
 }
 
+struct polyBaseNonTrivial { ~polyBaseNonTrivial(); virtual void f(); };
+
+void f(polyBaseNonTrivial* p, polyBaseNonTrivial* arr)
+{
+  polyBaseNonTrivial pbnt;
+  delete p;      // { dg-warning "non-virtual destructor might" }
+  delete [] arr;
+}
+
+struct polyDerivedNT : polyBaseNonTrivial { ~polyDerivedNT(); };
+
+void f(polyDerivedNT* p, polyDerivedNT* arr)
+{
+  polyDerivedNT pdnt;
+  delete p;      // { dg-warning "non-virtual destructor might" }
+  delete [] arr;
+}
+