C++ Logo

std-proposals

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sun, 27 Feb 2022 00:02:29 +0200
On Sat, 26 Feb 2022 at 23:40, organicoman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> I want to be free to initialize my members in any order i wish without triggering UB.

By all means, go ahead. Wrap your members in std::optional, and then
emplace into them in any order you like,
in your constructor body.

> Constructors are about user code.
> Destructors are about object layout.
> These are two orthogonal things.

That seems like a novel reinvention of C++, as by the original design,
they are not orthogonal, as the latter
undoes what the former does. An operation that mirrors another is not
orthogonal.

> Conclusion:
> With this approach, we can make C++ more intuitive and secure.

I daresay such extraordinary claims require extraordinary evidence.

> Not caring about members initialization order, frees the user from compiling his code mentaly before its compiler.
> We can enhance C++, without changing the current standard.

Well, if you wish to suggest a class-level annotation that specifies
that the members of a class so annotated can be initialized
in any order, that could be entertained, given a good enough
rationale. That could be such an enhancement. I doubt such an
enhancement
should be entertained without an explicit opt-in, considering that
there's likely fair amounts of code that relies on the
initialization/destruction
order guarantees that we have today.

Received on 2022-02-26 22:02:41