C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 28 Aug 2022 09:44:08 -0400
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.

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