Created attachment 29066 [details] Self-contained source file When using -Weffc++ with this code class Foo : public std::list<int> { }; the compiler warns that the base class "has a non-virtual destructor". While this is true, there is not much one can do about it. Suggestions: either remove the warning in these cases (when the problem is in the standard library), or add virtual destructors to standard library classes. If the compiler were to set a pre-processor variable when -Weffc++ is in effect, adding virtual destructors could be made conditional. /Lars Hamrén
(In reply to comment #0) > Created attachment 29066 [details] > Self-contained source file > > When using -Weffc++ with this code > > class Foo : public std::list<int> { }; > > the compiler warns that the base class "has a non-virtual destructor". While > this is true, there is not much one can do about it. Why not just not use -Weffc++ for STL. effc++ warnings are written from a book and they don't always make sense really. > If the compiler were to set a pre-processor variable when -Weffc++ is in > effect, adding virtual destructors could be made conditional. Then it would violate the one definition rule.
> Why not just not use -Weffc++ for STL. I can turn it off locally using a pragma, but that is rather ugly. I like to have as many warning flags turned on as possible. Not having false warnings is a great help. > effc++ warnings are written from a book > and they don't always make sense really. But often they do. Why not give them special treatment when they occur in system headers? > > If the compiler were to set a pre-processor variable when -Weffc++ is in > > effect, adding virtual destructors could be made conditional. > > Then it would violate the one definition rule. Agreed. Bad idea.
(In reply to comment #0) > When using -Weffc++ with this code > > class Foo : public std::list<int> { }; > > the compiler warns that the base class "has a non-virtual destructor". While > this is true, there is not much one can do about it. There are two things you can do: 1) don't use -Weffc++, it's flawed in many ways and noone's forcing you to use it 2) don't use public derivation from classes without virtual destructors, the warning is telling you about a potential problem. If you can't change the base class, take the hint and don't derive from it.
Adding Nathan to CC, since he's been touching this warning recently.
(In reply to Lars Hamrén from comment #0) > Suggestions: either remove the warning in these cases (when the problem is > in the standard library), or add virtual destructors to standard library > classes. I think this bug is simply INVALID. The warning is correct that you're deriving from a class without a virtual destructor, the fact the class is from the standard library doesn't change that. (Bug 56879 suggests limiting the warning to cases that matter, and Bug 16166 suggests there should be separate options for the various warnings controlled by -Weffc++, which would help here, but still wouldn't change the fact that deriving publicly from std::list is potentially bad). Giving std::list a virtual destructor is absolutely out of the question.