Boost logo

Boost :

Subject: Re: [boost] [exception] warning about non-virtual destructor - resolution?
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2012-04-16 12:14:29


Mathias Gaunard wrote:
> On 16/04/12 15:29, Daniel James wrote:
> In certain cases, the potential problem of a non-virtual destructor
> generates a warning when the declaration of the destructor is
> encountered. In other cases, the warning gets generated when a call to
> the destructor is made. In yet other cases, only if the call to the
> destructor is made through the delete operator.
I think they've gotten better at this.

If you put something like this on the stack you know the correct deconstructor is called and the Virtual table isn't even used so there's no reason to complain. I could put a class on the stack and call someone else with an interface to it. If they don't try to delete it good. No reason to complain.

Deleting a pointer to a final class is also fine.

You're really hard pressed to come up with situations where you would care about an extra virtual table entry and an extra indirection while deleting.

With C++11 you're even harder pressed to want to delete a non-final class which has virtual methods but no virtual deconstructor.

> Fixing the source of the problem is easier than adding kludges in every
> place the problem could end up being diagnosed.

I would add the deconstructor to someone's code unless he had a comment telling me exactly why not.

Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk