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

2024-10-26


1776. Replacement of class objects containing reference members

Section: 6.7.3  [basic.life]     Status: CD4     Submitter: Finland     Date: 2013-09-24

[Adopted at the June, 2016 meeting as document P0137R1.]

N3690 comment FI 15

The rules given in 6.7.3 [basic.life] paragraph 7 for when an object's lifetime can be ended and a new object created in its storage include the following restriction:

the type of the original object is not const-qualified, and, if a class type, does not contain any non-static data member whose type is const-qualified or a reference type

The intent of this restriction is to permit optimizers to rely upon the original values of const and reference members in their analysis of subsequent code. However, this makes it difficult to implement certain desirable functionality such as optional<T>; see this discussion for more details.

This rule should be reconsidered, at least as far as it applies to unions. If it is decided to keep the rule, acceptable programming techniques for writing safe code when replacing such objects should be outlined in a note.

(See also issue 1404, which will become moot if the restriction is lifted.)

Notes from the October, 2015 meeting:

See also paper P0137 and issue 2182.

Notes from the February, 2017 meeting.

The resolution of this issue also resolves issues 636 and 2151.