This is the mail archive of the gcc@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]

Re: Question w.r.t. `'class Foo' has virtual functions but non-virtualdestructor`warning.


Chris Lattner wrote:

I'm not sure I understand your point here. The library developer writes a class, and does not *want* it to be destroyed through the base class. As a library designer, I can intentionally make the dtor protected, making it pretty clear that delete should not be called on the base class.

I could agree that there should be no warning if the class declares a private operator delete. But, that kind of thing is a refinement.


The point is that it's a common error to forget the virtual destructor. If you're writing a library, and you put such a class in a header, you often want a warning *right then* -- not when a customer somewhere tries to use your library and uses delete on some class in your library.

With the current implementation of the warning, as a library designer, I am force to make the dtor virtual, even if there is no need in my library for it to be so.

Yes -- what if a user of your library will need it to be virtual?


Furthermore, even fine-grained warning control (at least on a per t-u basis) doesn't help me with this. As a library developer, forcing all

That's not fine-grained. Fine-grained is a pragma/attribute you can put on the class to say "don't issue this warning about this class."


--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304


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