The output is:
ctor
dtor
Exception: boom
The ctor/dtor are for "f1", and there is no ctor/dtor for the other "f2".
Which means the destructor does know from where to start destroying, right?
It destroyed only successfully constructed member objects, right?
But isn't the object's destructor when called, starts systematically destroying blindly from the last to first member object?
After all it is meant to destroy a fully constructed object, right?
So how did it know, that there is no need to destroy "f2"?
Did you get my points?
-------- Original message --------
From: Arvid Norberg <arvid.norberg@gmail.com>
Date: 2/26/22 3:30 AM (GMT+04:00)
To: std-proposals@lists.isocpp.org
Cc: organicoman <organicoman@yahoo.fr>
Subject: Re: [std-proposals] Relax condition for potentially invoked destructor in constructor
Connor, Arvind
An object at construction does not call its destructor, in case of exception or error.
A destructor exists only if the instantiated object had successfully been constructed.
Look at this example: (pay attention to the member "TheFree d" of the class "test")
[...]
Please run your examples through compiler explorer, or something similar, before posting.
The main mistake in your example is that division by zero does not throw an exception. It's undefined behavior.
If you had bothered to include a return statement in your Throw() function, your compiler would have told you.
When fixing your code to actually throw an exception, it works as one would expect.
You see Arvind? We are already paying the price of keeping record of constructed member objects.
No.
There's no need for record keeping since the order of construction is
known at compile time, statically. It's encoded in the machine code, not
in any run-time data structure.
So, you don't pay for it
(obviously there's the caveat that you pay some price for exception
handling, but I don't think that's what we're talking about).
--
Arvid Norberg