C++ Logo


Advanced search

Re: [std-proposals] Make calling the pseudo-destructor multiple times on an object undefined behavior?

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Sun, 28 Aug 2022 18:51:38 +0500
On 28/08/2022 18:44, Jason McKesson via Std-Proposals wrote:
> On Sun, Aug 28, 2022 at 9:06 AM blacktea hamburger via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>> Calling the destructor multiple times on a class object results in undefined behavior according to [class.dtor]/19:
>> Once a destructor is invoked for an object, the object's lifetime ends; the behavior is undefined if the destructor is invoked for an object whose lifetime has ended ([basic.life]).
>> However, similar thing doesn't apply to pseudo-destructor calls.
>> P0593R6 makes pseudo-destructor calls end objects' lifetimes. I wonder if adding such a provision would be useful.
> That already exists in [basic.life]/5:
> https://timsong-cpp.github.io/cppwp/n4861/basic.life#5.sentence-1
>> A program may end the lifetime of any object by reusing the storage which the object occupies or by explicitly calling a destructor or pseudo-destructor ([expr.prim.id.dtor]) for the object.

And where does it say that doing this on an out-of-lifetime object of scalar type is undefined behavior?

Received on 2022-08-28 13:51:44