Created on2012-04-02.00:00:00 last changed136 months ago
[Moved to DR at the February, 2014 meeting.]
Proposed resolution (September, 2013):
Change 11.4.5.3 [class.copy.ctor] paragraphs 31 and 32 as follows:
...This elision of copy/move operations, called copy elision, ispermitted in the following circumstances (which may be combined toeliminate multiple copies):
...
when theexception-declaration of an exception handler (Clause 14 [except]) declares an object of the same type (except forcv-qualification) as the exception object (14.2 [except.throw]), thecopy
/moveoperation can be omitted by treatingtheexception-declaration as an alias for the exception object ifthe meaning of the program will be unchanged except for the execution ofconstructors and destructors for the object declared bytheexception-declaration.[Note: there cannot be amove from the exception object because it is always an lvalue.—end note][Example:...
When the criteria for elision of a copy/move operation aremet, but not for anexception-declaration, or would bemet save for the fact that the source object is a function parameter, andthe object to be copied is designated by an lvalue, overload resolution toselect the constructor for the copy is first performed as if the objectwere designated by an rvalue. Ifthe first overload resolutionfailsor was not performed, or if the type of the firstparameter of the selected constructor is not an rvalue reference to theobject's type (possibly cv-qualified), overload resolution is performedagain, considering the object as an lvalue. [Note:...
The decision in 11.4.5.3 [class.copy.ctor] paragraph 32 on whether ornot a copy must be replaced by a move is phrased largely in terms ofwhen copy elision can be performed, as described in the precedingparagraph. In particular, the fourth bullet of paragraph 31 applies
when theexception-declaration of an exception handler (Clause 14 [except]) declares an object of the same type (exceptfor cv-qualification) as the exception object (14.2 [except.throw]), the copy/move operation can be omitted by treating theexception-declaration as an alias for the exception object ifthe meaning of the program will be unchanged except for the executionof constructors and destructors for the object declared by theexception-declaration.
The determination of “when the meaning of the program will beunchanged” is, in the general case, not practical. Copy elisionis optional, meaning that the compiler can simply choose not toperform it if the determination is too difficult. Choosing whetherto 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 wayto address this problem would be to eliminateexception-declarationsas a possible target for move-construction.
(See alsoissue 1579.)
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-11-24 00:00:00 | admin | set | status: dr -> c++14 |
| 2014-03-03 00:00:00 | admin | set | messages: +msg4959 |
| 2014-03-03 00:00:00 | admin | set | status: ready -> dr |
| 2013-10-14 00:00:00 | admin | set | messages: +msg4598 |
| 2013-10-14 00:00:00 | admin | set | status: drafting -> ready |
| 2012-11-03 00:00:00 | admin | set | status: open -> drafting |
| 2012-04-02 00:00:00 | admin | create | |