Title
Trivial destructors and object lifetime
Status
nad
Section
6.7.3 [basic.life]
Submitter
Johannes Schaub

Created on 2011-04-02.00:00:00 last changed 37 months ago

Messages

Date: 2021-02-15.00:00:00

Rationale (February, 2021):

The resolution of issue 2256 makes it clear that the destruction of an object, no matter how accomplished, ends its lifetime.

Date: 2011-08-15.00:00:00

Notes from the August, 2011 meeting:

CWG will need a paper exploring this topic before it can act on the issue.

Date: 2012-09-24.00:00:00

The Standard is self-contradictory regarding which destructor calls end the lifetime of an object. 6.7.3 [basic.life] paragraph 1 says,

The lifetime of an object of type T ends when:

  • if T is a class type with a non-trivial destructor (11.4.7 [class.dtor]), the destructor call starts, or

  • the storage which the object occupies is reused or released.

i.e., the lifetime of an object of a class type with a trivial destructor persists until its storage is reused or released. However, 11.4.7 [class.dtor] paragraph 15 says,

Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the destructor is invoked for an object whose lifetime has ended (6.7.3 [basic.life]).

implying that invoking any destructor, even a trivial one, ends the lifetime of the associated object. Similarly, 11.9.5 [class.cdtor] paragraph 1 says,

For an object with a non-trivial destructor, referring to any non-static member or base class of the object after the destructor finishes execution results in undefined behavior.

A similar question arises for pseudo-destructors for non-class types.

History
Date User Action Args
2021-02-17 00:00:00adminsetmessages: + msg6504
2021-02-17 00:00:00adminsetstatus: open -> nad
2012-09-24 00:00:00adminsetmessages: + msg3914
2011-04-02 00:00:00admincreate