Date: Wed, 18 Jan 2023 16:33:09 +0000
On Wed, 18 Jan 2023 at 16:02, Frank B. Brokken via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> Hi all,
>
> Recently I noticed item #10 in section 14.4 (Handling an exception),
> n4917.pdf
> (https://github.com/cplusplus/draft/releases/latest):
>
> 10 Referring to any non-static member or base class of an object in the
> handler for a function-try-block of a constructor or destructor for
> that object results in undefined behavior.
>
> Unfortunately, that item isn't elaborated, and somehow I find it
> puzzling. Cleary, if a class has composed data members then the
> destructors of
> those already constructed data members have been called when the execution
> reaches the constructor's function-try-block handler.
This seems to me a simple corollary of [class.cdtor], particularly
paragraph 1. I'd even question whether normative wording is necessary under
[except.handle]; this could probably be a note.
But why would referring to members of basic data types like 'int' be
> undefined?
If the data member is a member of a virtual base class, the vtable
(speaking concretely) and the offsets it contains necessary to compute the
address of that member may no longer be valid.
There is an issue that [class.cdtor] is actually more restrictive here than
[basic.life], meaning that operations that are allowed on an object fully
outside its lifetime (principally, referring to a non-virtual base class)
can no longer be performed once it is under construction or destruction.
I'm not sure if we've got around to opening a CWG issue there.
std-discussion_at_[hidden]> wrote:
> Hi all,
>
> Recently I noticed item #10 in section 14.4 (Handling an exception),
> n4917.pdf
> (https://github.com/cplusplus/draft/releases/latest):
>
> 10 Referring to any non-static member or base class of an object in the
> handler for a function-try-block of a constructor or destructor for
> that object results in undefined behavior.
>
> Unfortunately, that item isn't elaborated, and somehow I find it
> puzzling. Cleary, if a class has composed data members then the
> destructors of
> those already constructed data members have been called when the execution
> reaches the constructor's function-try-block handler.
This seems to me a simple corollary of [class.cdtor], particularly
paragraph 1. I'd even question whether normative wording is necessary under
[except.handle]; this could probably be a note.
But why would referring to members of basic data types like 'int' be
> undefined?
If the data member is a member of a virtual base class, the vtable
(speaking concretely) and the offsets it contains necessary to compute the
address of that member may no longer be valid.
There is an issue that [class.cdtor] is actually more restrictive here than
[basic.life], meaning that operations that are allowed on an object fully
outside its lifetime (principally, referring to a non-virtual base class)
can no longer be performed once it is under construction or destruction.
I'm not sure if we've got around to opening a CWG issue there.
Received on 2023-01-18 16:33:22