C++ Logo

sg12

Advanced search

Re: [ub] Non-virtual destructor call

From: Andrzej Krzemienski <akrzemi1_at_[hidden]>
Date: Fri, 13 Dec 2013 15:28:04 +0100
2013/12/13 Sebastian Redl <sebastian.redl_at_[hidden]>

> On 2013-12-13 13:56, Andrzej Krzemienski wrote:
> >
> > There is no harm, except that this is defined as UB. Could the rule be
> > relaxed to say that if the derived type is layout-compatible with the
> > base class and its destructor is implicitly declared or explicitly
> > defaulted, the behaviur is well defined?
>


> This would turn a rather simple rule...


Yes, I am proposing a more complex rule.


> You're not getting rid of a category of undefined behavior.


Correct. And that is not my goal.


> This is fragile.


Now it is all UB. Is it not fragile already?


> It's hard to teach.
>

I do not expect that this thing I am proposing would be taught. What you
would teach people doesn't change: use virtual or protected destructors in
base classes. This thing would be only exploited by programmers that feel
they know what they are doing -- at their own risk.


> the simpler rule is just better by virtue of being simpler.
>

True.

Regards,
&rzej

Received on 2013-12-13 15:28:05