C++ Logo

sg12

Advanced search

Re: [ub] Non-virtual destructor call

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 13 Dec 2013 19:51:25 +0200
On 13 December 2013 17:28, Andrzej Krzemienski <akrzemi1_at_[hidden]> wrote:
>
>
>
> 2013/12/13 Ville Voutilainen <ville.voutilainen_at_[hidden]>
>>
>>
>> Why don't you do
>> std::function<void(T)>*fun = new std::function<void(T)>(Callback{});
>> delete fun;
>> instead? Apply auto* where necessary.
>
>
> Well, it is not a real-life use. I do not have to solve this problem in any
> of my projects. I had a hypothesis that "using veneers is safe", i.e. If I
> derive from a type that does not have virtual functions but I do not add any
> changes to the layout, it is a safe thing to do. It turns out that 5.3.5/3
> makes it unsafe, but for no good reason.
>
> Well, having rules simpler has merit, but it also prevents certain styles of
> programming.


Yeah. I have only ever used veneers that get passed out from their creation
functions by value, and surprisingly often such veneers have been construction
veneers for containers, so I haven't run into dynamic allocation of the result
type much.

Received on 2013-12-13 18:51:27