aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorPawel Sikora <pluto@pld-linux.org>2007-08-20 15:08:24 +0000
committerJason Merrill <jason@gcc.gnu.org>2007-08-20 11:08:24 -0400
commit43f1474491615c9c895716ef0e2a01d0280b1ef1 (patch)
tree89dd492f0749e3baf99fc3690e6259c93197aed0 /gcc/cp/class.c
parent01a2a2f512b20d95ac7cc229662787fa0babfdf0 (diff)
downloadgcc-43f1474491615c9c895716ef0e2a01d0280b1ef1.zip
gcc-43f1474491615c9c895716ef0e2a01d0280b1ef1.tar.gz
gcc-43f1474491615c9c895716ef0e2a01d0280b1ef1.tar.bz2
re PR c++/7302 (-Wnon-virtual-dtor should't complain of protected dtor)
PR c++/7302 * cp/class.c (finish_struct_1): Warn when a class has virtual functions and accessible non-virtual destructor. * doc/invoke.texi (-Wnon-virtual-dtor): Update documentation. * g++.dg/warn/Wnvdtor-2.C: New testcase. From-SVN: r127649
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index f41033c..07dc954 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5120,17 +5120,19 @@ finish_struct_1 (tree t)
tree dtor;
dtor = CLASSTYPE_DESTRUCTORS (t);
- /* Warn only if the dtor is non-private or the class has
- friends. */
if (/* An implicitly declared destructor is always public. And,
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",
- t);
+ && (/* public non-virtual */
+ (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
+ || (/* non-public non-virtual with friends */
+ (TREE_PRIVATE (dtor) || TREE_PROTECTED (dtor))
+ && (CLASSTYPE_FRIEND_CLASSES (t)
+ || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))))))
+ warning (OPT_Wnon_virtual_dtor,
+ "%q#T has virtual functions and accessible"
+ " non-virtual destructor", t);
}
complete_vars (t);