C++ Logo


Advanced search

Re: [std-proposals] Relax condition for potentially invoked destructor in constructor

From: Arvid Norberg <arvid.norberg_at_[hidden]>
Date: Sat, 26 Feb 2022 16:56:54 +0100
On Sat, Feb 26, 2022 at 4:43 PM organicoman via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> [...]
> At destructor invocation time, the destructor finds all the *member
> subobjects *in their correct places and it starts destroying from
> whatever order the standard wants.

The order the standard wants is the opposite order of initialization.

> Why? Because the destructor is only available when all the subobjects
> exist and are in their places.
> Does it need to know how the object was constructed? NO

It does, since it needs to destroy the objects in the opposite order of

> How hard is this to understand?

It sounds like you consider it unimportant to destroy objects in the
opposite order of construction. It's a pretty important feature actually,
perhaps more important than first meets the eye.

The only thing that matters to a destructor is that the object finished
> construction successfully.

No, the initialization order also matters. Try to think of examples where
it really matters.

Arvid Norberg

Received on 2022-02-26 15:57:07