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.


On Fri, Mar 04, 2005 at 08:06:27PM -0600, Chris Lattner wrote:
> In my mind, the times you want to silence the warning (without defining 
> the virtual dtor) are when you *know* that it will never be used that way, 
> because it's part of the contract of the class.

In my view, if a class defines virtual functions, then this implies
that the class is intended to be derived from, so a non-virtual
destructor is asking for trouble and should be warned about, even
if there is no "delete".

If it has no virtual functions, then (since C++ has no "final" keyword),
the lack of a virtual destructor should not trigger a warning even
if the object is deleted.

> >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.
> 
> I think this would be a great refinement (if you extended it to protected 
> dtors also).

Nope.  If there's a protected destructor, then that means that it will
form only *part* of the destructor of the derived class, so it's still
an error if a pointer to Base can delete a Derived.  Solving the points-to
problem exactly is undecidable, so ...



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