[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395 --- Comment #9 from Jonathan Wakely --- (In reply to marc from comment #8) > I don't think Effective C++ is the benchmark any more I've been trying to say that for years and people keep insisting they want warnings based on advice from the late '90s. Warnings that don't even accurately follow that advice.
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395 --- Comment #8 from marc at kdab dot com --- I don't think Effective C++ is the benchmark any more, so water under bridges that have already burned, but fwiw: contrary to C.127 these days, I learned this rule as "A base class's destructor should be public and virtual or else protected and non-virtual" (implying that, otherwise, don't use inheritance, but aggregation; could've been from CS:101 from Andrej and Herb).
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395 --- Comment #7 from Jonathan Wakely --- (In reply to Eric Gallager from comment #6) > Note that clang goes even farther in splitting up -Wdelete-non-virtual-dtor > into different warnings based on whether the dtor is abstract or not: > https://clang.llvm.org/docs/DiagnosticsReference.html#wdelete-abstract-non- > virtual-dtor That's about whether the *class* is abstract or not. There's no such thing as an abstract non-virtual destructor. I don't see much benefit to splitting it up. It's undefined behaviour either way, so I don't see a valid use case for enabling the warning in some cases but not others.
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395 --- Comment #6 from Eric Gallager --- (In reply to Jonathan Wakely from comment #5) > private inheritance doesn't mean the destructor can't be called with the > wrong static type > > class Foo { > public: > ~Foo() {} > virtual void f() { } > }; > > class Bar : private Foo { > public: > Foo* get() { return this; } > }; > > int main() > { > Bar* b = new Bar; > delete b->get(); > } > > as stated in PR 16166 comment 3, the 3rd edition of Effective C++ changes > the guideline, and -Wdelete-non-virtual-dtor is usually a better option > anyway Note that clang goes even farther in splitting up -Wdelete-non-virtual-dtor into different warnings based on whether the dtor is abstract or not: https://clang.llvm.org/docs/DiagnosticsReference.html#wdelete-abstract-non-virtual-dtor Maybe gcc should do likewise?
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395 --- Comment #5 from Jonathan Wakely redi at gcc dot gnu.org 2012-01-05 17:13:02 UTC --- private inheritance doesn't mean the destructor can't be called with the wrong static type class Foo { public: ~Foo() {} virtual void f() { } }; class Bar : private Foo { public: Foo* get() { return this; } }; int main() { Bar* b = new Bar; delete b-get(); } as stated in PR 16166 comment 3, the 3rd edition of Effective C++ changes the guideline, and -Wdelete-non-virtual-dtor is usually a better option anyway
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
--- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-11 16:29 --- Confirmed. -- What|Removed |Added Severity|normal |enhancement Status|UNCONFIRMED |NEW Ever Confirmed||1 Keywords||diagnostic Last reconfirmed|-00-00 00:00:00 |2005-07-11 16:29:04 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
--- Additional Comments From mutz at kde dot org 2005-07-10 18:54 --- class Bar : public Foo {}; Of course, that should read: class Bar : private Foo {}; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
--- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-10 19:05 --- I think this is a dup of bug 16168 or at least a related issue. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395
[Bug c++/22395] -Weffc++ shouldn't warn about non-virtual dtor of private subclasses
--- Additional Comments From mutz at kde dot org 2005-07-10 19:16 --- Related it may be, but different it is. bug 16168 is about subclasses that don't have virtual methods, but even in the case of the private inheritance from a base class having virtual methods, the warning should not be triggered. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22395