Title
Delegating constructors, destructors, and std::exit
Status
cd2
Section
6.9.3.3 [basic.start.dynamic]
Submitter
Michael Wong

Created on 2009-02-12.00:00:00 last changed 179 months ago

Messages

Date: 2009-10-15.00:00:00

[Voted into WP at October, 2009 meeting.]

Date: 2009-07-15.00:00:00

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.4 [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...
Date: 2009-07-15.00:00:00

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.

Date: 2009-03-15.00:00:00

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.

Date: 2016-02-15.00:00:00

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.4 [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?

History
Date User Action Args
2010-03-29 00:00:00adminsetstatus: dr -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2426
2009-11-08 00:00:00adminsetstatus: ready -> dr
2009-08-03 00:00:00adminsetmessages: + msg2141
2009-08-03 00:00:00adminsetmessages: + msg2140
2009-08-03 00:00:00adminsetstatus: drafting -> ready
2009-03-23 00:00:00adminsetmessages: + msg1943
2009-02-12 00:00:00admincreate