This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++] Weffc++/Wnon-virtual-dtor confusion
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: Nathan Sidwell <nathan at acm dot org>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 4 Apr 2014 18:38:09 +0200
- Subject: Re: [C++] Weffc++/Wnon-virtual-dtor confusion
- Authentication-results: sourceware.org; auth=none
- References: <533967BE dot 1020301 at acm dot org>
On 2014.03.31 at 14:03 +0100, Nathan Sidwell wrote:
> This patch fixes some unexpected behaviour of the Weffc++ and Wnon-virtual-dtor
> flags. The documentation for the latter says it's also enabled by Weffc++, but
> that's untrue.
>
> The current behaviour of Weffc++ is to warn about any non-virtual dtor in a
> non-polymorphic base class (relying on the below described -Wnon-virtual-dtor
> case to catch polymorphic classes). Since Edition 3 of Scott Meyer's book, the
> rule has been that it only applies to polymorphic classes. I.e. a polymorphic
> class should not have an accessible non-virtual destructor and all of its bases
> should be likewise. (it's possible earlier editions stated this rule too, but
> 3rd ed was what I could find).
>
> The current behaviour of Wnon-virtual-dtor is to complain about accessible
> non-virtual dtors in polymorphic classes. This is what one expects.
>
> One surprising outcome of the current implementation is that -Weffc++
> -Wno-non-virtual-dtor still complains about the lack of virtual dtors in base
> classes.
>
> This patch:
> 1) Clarifies the documentation for -Wnon-virtual-dtor to be for polymorphic
> classes and bases of such classes. (i.e. move the 3rd ed Weffc++ behaviour into
> this flag).
I'm not sure that this is a good idea. This changes the existing
behavior of -Wnon-virtual-dtor and causes hundreds of new warnings when
building LLVM. Wouldn't it make more sense to move the 3rd ed Weffc++
behavior to the -Weffc++ flag alone?
--
Markus