|
Boost : |
Subject: Re: [boost] [exception] warning about non-virtual destructor - resolution?
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-04-16 16:51:59
On Monday 16 April 2012 12:12:21 Emil Dotchevski wrote:
> >
> > 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.
>
> The reason to care isn't performance. I tend to take the virtual keyword
> seriously when I read code: it is an invitation to call the function
> through a base type pointer. In this case it would be a bug if the
> destructor is ever called virtually. You'll know your compiler is wrong
> when it tries to "protect" you from conscious and correct design decisions.
IMHO, you are taking it too seriously. If you want to disable the call to the
destructor, you typically declare it private or protected. Whether it is
virtual or not is another story and irrelevant to the access restriction
(which is actually what you're trying to impose). And declaring it virtual
doesn't make the code uglier. In fact, compared to all the machinery required
to disable the warning for every compiler, it is a cleaner solution.
PS: Don't get me wrong, I too am annoyed by spurious warnings sometimes and I
do not support the "no-warnings" policies in general. However, I tend to
follow the "minimal code ugliness" criteria in making the decision whether to
disable the warning or adjust the code.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk