This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++] Weffc++/Wnon-virtual-dtor confusion


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).

2) As different editions of Scott's book renumber the rules, I removed the numbering in Weffc++ and merged the two separate lists.

3) Made -Wnon-virtual-dtor get set from -Weffc++.

4) Moved the check for nonvirtual dtors in base classes to after we determine the class is polymorphic. Warn for all bases, not just the non-polymorphic ones.

5) Made that check trigger on -Wnon-virtual-dtor, not Weffc++.

I removed the 3 scattered tests for non-virtual dtor checking and updated and cloned the warn/Wnvdtor.C test to check for the interactions between the two flags.

built & tested on i686-pc-linux-gnu. I'll commit in a few days, unless there are comments.

nathan

Attachment: all.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]