C++ Logo


Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Sun, 27 Feb 2022 02:10:53 +0400
🏳🏳🏳Sent from my Galaxy
-------- Original message --------From: Ville Voutilainen <ville.voutilainen_at_[hidden]> Date: 2/27/22 2:02 AM (GMT+04:00) To: sotrdg sotrdg via Std-Proposals <std-proposals_at_[hidden]> Cc: organicoman <organicoman_at_[hidden]> Subject: Re: [std-proposals] Relax condition for potentially invoked
  destructor in constructor 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 thenemplace 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 latterundoes what the former does. An operation that mirrors another is notorthogonal.> 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 specifiesthat the members of a class so annotated can be initializedin any order, that could be entertained, given a good enoughrationale. That could be such an enhancement. I doubt such anenhancementshould be entertained without an explicit opt-in, considering thatthere's likely fair amounts of code that relies on theinitialization/destructionorder guarantees that we have today.

Received on 2022-02-26 22:11:00