Title
Initializing variant members with non-trivial destructors
Status
cd4
Section
14.3 [except.ctor]
Submitter
Vinny Romano

Created on 2014-02-12.00:00:00 last changed 87 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2014-07-15.00:00:00

Proposed Resolution (July, 2014):

Change 14.3 [except.ctor] paragraph 2 as follows:

An object of any storage duration whose initialization or destruction is terminated by an exception will have destructors executed for all of its fully constructed subobjects (excluding the variant members of a union-like class), that is, for subobjects for which the principal constructor (11.9.3 [class.base.init]) has completed execution and the destructor has not yet begun execution, except that in the case of destruction, the variant members of a union-like class are not destroyed. Similarly, if the non-delegating constructor...
Date: 2014-06-15.00:00:00

Notes from the June, 2014 meeting:

CWG favored removing the exclusion of variant members from the destruction following an exception during construction, though not during destruction. If the active member of the union has changed between the initialization and destruction, the behavior is undefined.

Date: 2014-02-12.00:00:00

According to 14.3 [except.ctor] paragraph 2,

An object of any storage duration whose initialization or destruction is terminated by an exception will have destructors executed for all of its fully constructed subobjects (excluding the variant members of a union-like class), that is, for subobjects for which the principal constructor (11.9.3 [class.base.init]) has completed execution and the destructor has not yet begun execution.

This introduces a potential leak if a variant member is initialized and has a non-trivial destructor. If the assumption can't be made that such an initialized member is the active member at the time an exception occurs so that it can be destroyed, perhaps variant members of types having a non-trivial destructor should be prohibited.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5422
2014-11-24 00:00:00adminsetstatus: tentatively ready -> dr
2014-10-13 00:00:00adminsetmessages: + msg5145
2014-10-13 00:00:00adminsetstatus: drafting -> tentatively ready
2014-07-07 00:00:00adminsetmessages: + msg5099
2014-07-07 00:00:00adminsetstatus: open -> drafting
2014-02-12 00:00:00admincreate