[This relates to gcc PR c++/7302 and Debian bug 356316.] Matthias Klose wrote: > Hi, > > please could you send this patch to [EMAIL PROTECTED], together > with a ChangeLog entry?
I was holding off on this until I had time to deal with documentation and test cases as well. Now that I've done that (I think), here's a complete patch: diff -u gcc/cp/class.c~ gcc/cp/class.c --- gcc/cp/class.c~ 2006-03-11 13:28:45.000000000 +0000 +++ gcc/cp/class.c 2006-03-11 13:30:19.000000000 +0000 @@ -5073,10 +5073,9 @@ if it were virtual, we would have created it by now. */ !dtor || (!DECL_VINDEX (dtor) - && (!TREE_PRIVATE (dtor) - || CLASSTYPE_FRIEND_CLASSES (t) - || DECL_FRIENDLIST (TYPE_MAIN_DECL (t))))) - warning (0, "%q#T has virtual functions but non-virtual destructor", + && !(TREE_PRIVATE (dtor) || TREE_PROTECTED (dtor)))) + warning (0, + "%q#T has virtual functions and public non-virtual destructor", t); } diff -u gcc/doc/invoke.texi~ gcc/doc/invoke.texi --- gcc/doc/invoke.texi~ 2006-04-23 23:03:01.000000000 +0000 +++ gcc/doc/invoke.texi 2006-04-23 23:06:15.000000000 +0000 @@ -1726,8 +1726,9 @@ @item -Wnon-virtual-dtor @r{(C++ only)} @opindex Wnon-virtual-dtor -Warn when a class appears to be polymorphic, thereby requiring a virtual -destructor, yet it declares a non-virtual one. +Warn when a class has virtual functions and a public non-virtual +destructor, in which case it would be possible but unsafe to delete +an instance of a derived class through a pointer to the first class. This warning is enabled by @option{-Wall}. @item -Wreorder @r{(C++ only)} diff -u /dev/null gcc/testsuite/g++.dg/warn/Wnvdtor-2.C --- /dev/null 2006-04-16 14:56:53.000000000 +0000 +++ gcc/testsuite/g++.dg/warn/Wnvdtor-2.C 2006-04-23 16:11:40.000000000 +0000 @@ -0,0 +1,10 @@ +// { dg-options "-Wnon-virtual-dtor" } +// PR c++/7302 + +class foo +{ // { dg-bogus "non-virtual destructor" } +public: + virtual void bar(); +protected: + ~foo(); +}; -- END -- and an entry for the changelog: 2006-04-23 Ben Hutchings <[EMAIL PROTECTED]> PR c++/7302 * class.c: Do not warn about protected or private non-virtual destructors. -- END -- The test seems to pass but I'm don't understand the GCC test system well enough to be sure it is actually being run. I would appreciate it if someone else could check that for me. Ben. -- Ben Hutchings Life is what happens to you while you're busy making other plans. - John Lennon
signature.asc
Description: Digital signature