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

2024-11-11


2930. Unclear term "copy/move operation" in specification of copy elision

Section: 11.9.6  [class.copy.elision]     Status: tentatively ready     Submitter: Gabriel Dos Reis     Date: 2024-08-16

The specification of copy elision in 11.9.6 [class.copy.elision] uses the undefined term "copy/move operation", even though the constructor actually selected might not be a copy or move constructor as specified in 11.4.5.3 [class.copy.ctor]. It is thus unclear whether copy elision can be applied even in the case a non-copy/move constructor is selected.

Proposed resolution (approved by CWG 2024-10-11):

Change in 11.9.6 [class.copy.elision] paragraph 1 through 3 as follows:

When certain criteria are met, an implementation is allowed to omit the copy/move construction of creation of a class object, even if the selected constructor selected for the copy/move operation and/or the destructor for the object have side effects. In such cases, the implementation treats the source and target of the omitted copy/move operation initialization as simply two different ways of referring to the same object. If the first parameter of the selected constructor is an rvalue reference to the object's type, the destruction of that object occurs when the target would have been destroyed; otherwise, the destruction occurs at the later of the times when the two objects would have been destroyed without the optimization. [ Footnote: Note: Because only one object is destroyed instead of two, and one copy/move constructor is not executed the creation of one object is omitted, there is still one object destroyed for each one constructed. -- end footnote note ] This elision of copy/move operations object creation, called copy elision, is permitted in the following circumstances (which may be combined to eliminate multiple copies):