Commit 38f09da3 by Nathan Sidwell Committed by Nathan Sidwell

invoke (Wnon-virtual-dtor): Update to match implementation.

	* doc/invoke (Wnon-virtual-dtor): Update to match implementation.
	(Weffc++): Likewise.

	cp/
	* class.c (check_bases_and_members): Warn about non-virtual dtors
	in public bases only.  Check warn_ecpp before complaining about
	non-polymorphic bases.

	testsuite/
	* g++.dg/warn/Wnvdtor-2.C: Add more cases.
	* g++.dg/warn/Wnvdtor-3.C: Likewise.
	* g++.dg/warn/Wnvdtor-4.C: Likewise.

From-SVN: r209212
parent 55f31857
2014-04-08 Nathan Sidwell <nathan@codesourcery.com>
* doc/invoke (Wnon-virtual-dtor): Update to match implementation.
(Weffc++): Likewise.
2014-04-07 Jan Hubicka <hubcika@ucw.cz> 2014-04-07 Jan Hubicka <hubcika@ucw.cz>
* ipa-devirt.c (maybe_record_node): When node is not recorded, * ipa-devirt.c (maybe_record_node): When node is not recorded,
......
2014-04-08 Nathan Sidwell <nathan@codesourcery.com>
* class.c (check_bases_and_members): Warn about non-virtual dtors
in public bases only. Check warn_ecpp before complaining about
non-polymorphic bases.
2014-04-04 Fabien Chêne <fabien@gcc.gnu.org> 2014-04-04 Fabien Chêne <fabien@gcc.gnu.org>
* decl.c (duplicate_decls): Check for the return of warning_at * decl.c (duplicate_decls): Check for the return of warning_at
......
...@@ -5570,21 +5570,24 @@ check_bases_and_members (tree t) ...@@ -5570,21 +5570,24 @@ check_bases_and_members (tree t)
TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t); TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t); TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
/* Warn if a base of a polymorphic type has an accessible /* Warn if a public base of a polymorphic type has an accessible
non-virtual destructor. It is only now that we know the class is non-virtual destructor. It is only now that we know the class is
polymorphic. Although a polymorphic base will have a already polymorphic. Although a polymorphic base will have a already
been diagnosed during its definition, we warn on use too. */ been diagnosed during its definition, we warn on use too. */
if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor) if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor)
{ {
tree binfo, base_binfo; tree binfo = TYPE_BINFO (t);
vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
tree base_binfo;
unsigned i; unsigned i;
for (binfo = TYPE_BINFO (t), i = 0; for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{ {
tree basetype = TREE_TYPE (base_binfo); tree basetype = TREE_TYPE (base_binfo);
if (accessible_nvdtor_p (basetype)) if ((*accesses)[i] == access_public_node
&& (TYPE_POLYMORPHIC_P (basetype) || warn_ecpp)
&& accessible_nvdtor_p (basetype))
warning (OPT_Wnon_virtual_dtor, warning (OPT_Wnon_virtual_dtor,
"base class %q#T has accessible non-virtual destructor", "base class %q#T has accessible non-virtual destructor",
basetype); basetype);
......
...@@ -2671,10 +2671,10 @@ the compiler to never throw an exception. ...@@ -2671,10 +2671,10 @@ the compiler to never throw an exception.
@opindex Wnon-virtual-dtor @opindex Wnon-virtual-dtor
@opindex Wno-non-virtual-dtor @opindex Wno-non-virtual-dtor
Warn when a class has virtual functions and an accessible non-virtual Warn when a class has virtual functions and an accessible non-virtual
destructor itself or in a base class, or has in which case it is destructor itself or in an accessible polymorphic base class, in which
possible but unsafe to delete an instance of a derived class through a case it is possible but unsafe to delete an instance of a derived
pointer to the base class. This warning is automatically enabled if class through a pointer to the class itself or base class. This
@option{-Weffc++} is specified. warning is automatically enabled if @option{-Weffc++} is specified.
@item -Wreorder @r{(C++ and Objective-C++ only)} @item -Wreorder @r{(C++ and Objective-C++ only)}
@opindex Wreorder @opindex Wreorder
...@@ -2744,7 +2744,9 @@ Never overload @code{&&}, @code{||}, or @code{,}. ...@@ -2744,7 +2744,9 @@ Never overload @code{&&}, @code{||}, or @code{,}.
@end itemize @end itemize
This option also enables @option{-Wnon-virtual-dtor}, which is also This option also enables @option{-Wnon-virtual-dtor}, which is also
one of the effective C++ recommendations. one of the effective C++ recommendations. However, the check is
extended to warn about the lack of virtual destructor in accessible
non-polymorphic bases classes too.
When selecting this option, be aware that the standard library When selecting this option, be aware that the standard library
headers do not obey all of these guidelines; use @samp{grep -v} headers do not obey all of these guidelines; use @samp{grep -v}
......
2014-04-08 Nathan Sidwell <nathan@codesourcery.com>
* g++.dg/warn/Wnvdtor-2.C: Add more cases.
* g++.dg/warn/Wnvdtor-3.C: Likewise.
* g++.dg/warn/Wnvdtor-4.C: Likewise.
2014-04-07 Eric Botcazou <ebotcazou@adacore.com> 2014-04-07 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/test_raise_from_pure.adb: UnXFAIL for ARM. * gnat.dg/test_raise_from_pure.adb: UnXFAIL for ARM.
......
...@@ -54,4 +54,23 @@ public: ...@@ -54,4 +54,23 @@ public:
}; };
struct H {}; struct H {};
struct I : H {};
struct I1 : H
{};
struct I2 : private H
{};
struct J1 : H
{ virtual ~J1 ();};
struct J2 : private H
{ virtual ~J2 ();};
struct K // { dg-warning "accessible non-virtual destructor" }
{
virtual void k ();
};
struct L1 : K // { dg-warning "accessible non-virtual destructor" }
{virtual ~L1 ();};
struct L2 : private K
{virtual ~L2 ();};
...@@ -53,4 +53,23 @@ public: ...@@ -53,4 +53,23 @@ public:
}; };
struct H {}; struct H {};
struct I : H {};
struct I1 : H
{};
struct I2 : private H
{};
struct J1 : H // { dg-warning "accessible non-virtual destructor" }
{ virtual ~J1 ();};
struct J2 : private H
{ virtual ~J2 ();};
struct K // { dg-warning "accessible non-virtual destructor" }
{
virtual void k ();
};
struct L1 : K // { dg-warning "accessible non-virtual destructor" }
{virtual ~L1 ();};
struct L2 : private K
{virtual ~L2 ();};
...@@ -53,4 +53,23 @@ public: ...@@ -53,4 +53,23 @@ public:
}; };
struct H {}; struct H {};
struct I : H {};
struct I1 : H
{};
struct I2 : private H
{};
struct J1 : H
{ virtual ~J1 ();};
struct J2 : private H
{ virtual ~J2 ();};
struct K
{
virtual void k ();
};
struct L1 : K
{virtual ~L1 ();};
struct L2 : private K
{virtual ~L2 ();};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment