Title
Criteria for move-construction
Status
c++14
Section
15.8 [class.copy]
Submitter
John Spicer

Created on 2012-04-02.00:00:00 last changed 68 months ago

Messages

Date: 2014-02-15.00:00:00

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

Date: 2013-09-15.00:00:00

Proposed resolution (September, 2013):

Change 15.8 [class.copy] paragraphs 31 and 32 as follows:

...This elision of copy/move operations, called copy elision, is permitted in the following circumstances (which may be combined to eliminate multiple copies):

  • ...

  • when the exception-declaration of an exception handler (Clause 18 [except]) declares an object of the same type (except for cv-qualification) as the exception object (18.1 [except.throw]), the copy/move operation can be omitted by treating the exception-declaration as an alias for the exception object if the meaning of the program will be unchanged except for the execution of constructors and destructors for the object declared by the exception-declaration. [Note: there cannot be a move from the exception object because it is always an lvalue. —end note]

[Example:...

When the criteria for elision of a copy/move operation are met, but not for an exception-declaration, or would be met save for the fact that the source object is a function parameter, and the object to be copied is designated by an lvalue, overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If the first overload resolution fails or was not performed, or if the type of the first parameter of the selected constructor is not an rvalue reference to the object's type (possibly cv-qualified), overload resolution is performed again, considering the object as an lvalue. [Note:...

Date: 2013-10-14.00:00:00
N3690 comment CA 23

The decision in 15.8 [class.copy] paragraph 32 on whether or not a copy must be replaced by a move is phrased largely in terms of when copy elision can be performed, as described in the preceding paragraph. In particular, the fourth bullet of paragraph 31 applies

when the exception-declaration of an exception handler (Clause 18 [except]) declares an object of the same type (except for cv-qualification) as the exception object (18.1 [except.throw]), the copy/move operation can be omitted by treating the exception-declaration as an alias for the exception object if the meaning of the program will be unchanged except for the execution of constructors and destructors for the object declared by the exception-declaration.

The determination of “when the meaning of the program will be unchanged” is, in the general case, not practical. Copy elision is optional, meaning that the compiler can simply choose not to perform it if the determination is too difficult. Choosing whether to do a copy or a move, however, is mandatory, even if the copy is elided, and such a broad criterion is not appropriate. Probably the best way to address this problem would be to eliminate exception-declarations as a possible target for move-construction.

(See also issue 1579.)

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: + msg4959
2014-03-03 00:00:00adminsetstatus: ready -> dr
2013-10-14 00:00:00adminsetmessages: + msg4598
2013-10-14 00:00:00adminsetstatus: drafting -> ready
2012-11-03 00:00:00adminsetstatus: open -> drafting
2012-04-02 00:00:00admincreate