This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-09-28


3047. Calling destructors on out-of-lifetime objects

Section: 6.8.4  [basic.life]     Status: open     Submitter: Jiang An     Date: 2025-06-18

(From submission #717.)

Calling a non-static member function for an ou8t-of-lifetime object is undefined behavior according to 6.8.4 [basic.life] paragraph 7 and paragraph 8. There is no reason to normatively duplicate that general rule for a subset of destructors in 6.8.4 [basic.life] paragraph 11.

Possible resolution:

Change in 6.8.4 [basic.life] paragraph 11 as follows:

[Note: If a program ends the lifetime of an object of type T with static (6.8.6.2 [basic.stc.static]), thread (6.8.6.3 [basic.stc.thread]), or automatic (6.8.6.4 [basic.stc.auto]) storage duration and if T has a non-trivial destructor for which the destructor will be called implicitly (8.10 [stmt.dcl], 6.10.3.4 [basic.start.term]), and another object of the original type does not occupy that same storage location when the implicit destructor call takes place, the behavior of the program is undefined. This is true even if the block is exited with an exception. [Example 4: ... —end example] -- end note]