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

2024-03-20


776. Delegating constructors, destructors, and std::exit

Section: 6.9.3.3  [basic.start.dynamic]     Status: CD2     Submitter: Michael Wong     Date: 12 February, 2009

[Voted into WP at October, 2009 meeting.]

According to 6.9.3.3 [basic.start.dynamic] paragraph 1,

Destructors (11.4.7 [class.dtor]) for initialized objects with static storage duration are called as a result of returning from main and as a result of calling std::exit (17.5 [support.start.term]).

It is unclear, in the presence of delegating constructors, exactly what an “initialized object” is. 6.7.3 [basic.life] paragraph 1 says that the lifetime of an object does not begin until it is completely initialized, i.e., when its principal constructor finishes execution. 14.3 [except.ctor] paragraph 2 says that an exception during the construction of class object only invokes destructors for fully-constructed base and member sub-objects (those for which the principal constructor has completed). On the other hand, the destructor for a complete class object is called if its non-delegating constructor has completed, even if the principal constructor has not yet finished. Which of these models is appropriate for the behavior of std::exit?

Notes from the March, 2009 meeting:

The CWG agreed that the destructor for a complete object should be called by std::exit if its non-delegating constructor has finished, just as for an exception.

Notes from the July, 2009 meeting:

The CWG decided that the direction adopted at the March, 2009 meeting was incorrect. Instead, the model should be the way completely-constructed base and member subobjects are handled: their destructors are called when an exception is thrown but not when std::exit is called.

Proposed resolution (July, 2009):

Change 6.9.3.3 [basic.start.dynamic] paragraph 1 as follows:

Destructors (11.4.7 [class.dtor]) for initialized objects (that is, objects whose lifetime (6.7.3 [basic.life]) has begun) with static storage duration are called as a result of returning from main and as a result of calling std::exit (17.5 [support.start.term]). Destructors for initialized objects with thread storage duration...