From: Jonathan Wakely Date: Fri, 1 Jul 2011 22:24:42 +0000 (+0000) Subject: re PR c++/49605 (-Wdelete-non-virtual-dtor is not picky enough) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2ab8a0f88198a43c90cef65f1701beaaa98f525;p=gcc.git re PR c++/49605 (-Wdelete-non-virtual-dtor is not picky enough) 2011-07-01 Jonathan Wakely PR c++/49605 * init.c (build_delete): Only warn for sfk_deleting_destructor. From-SVN: r175771 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 81252992e36..6ffebf1b0fe 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-07-01 Jonathan Wakely + + PR c++/49605 + * init.c (build_delete): Only warn for sfk_deleting_destructor. + 2011-07-01 Jakub Jelinek * Make-lang.in (cp/decl.o): Depend on pointer-set.h. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index f80c475f7ac..7970b9ac476 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c13fd9f5da3..5d44545dd84 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-07-01 Jonathan Wakely + + PR c++/49605 + * g++.dg/warn/delete-non-virtual-dtor.C: Adjust. + 2011-07-01 Jason Merrill PR c++/48261 diff --git a/gcc/testsuite/g++.dg/warn/delete-non-virtual-dtor.C b/gcc/testsuite/g++.dg/warn/delete-non-virtual-dtor.C index 9849b1edfa8..c4acbde26a1 100644 --- a/gcc/testsuite/g++.dg/warn/delete-non-virtual-dtor.C +++ b/gcc/testsuite/g++.dg/warn/delete-non-virtual-dtor.C @@ -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; +} +