Title
Copy elision and move construction of function parameters
Status
c++11
Section
_N4750_.15.8 [class.copy]
Submitter
DE

Created on 2010-08-03.00:00:00 last changed 96 months ago

Messages

Date: 2010-11-15.00:00:00

[Voted into the WP at the November, 2010 meeting.]

Date: 2010-09-15.00:00:00

Proposed resolution (September, 2010):

  1. Change _N4750_.15.8 [class.copy] paragraph 34 bullets 1 and 2 as follows:

    • in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object (other than a function or catch-clause parameter) with the same cv-unqualified type as the function return type, the copy/move operation can be omitted by constructing the automatic object directly into the function's return value

    • in a throw-expression, when the operand is the name of a non-volatile automatic object (other than a function or catch-clause parameter) whose scope does not extend beyond the end of the innermost enclosing try-block (if there is one), the copy/move operation from the operand to the exception object (14.2 [except.throw]) can be omitted by constructing the automatic object directly into the exception object

    Change _N4750_.15.8 [class.copy] paragraph 35 as follows:

    When the criteria for elision of a copy operation are met, 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...
[Drafting note: the change to paragraph 35 intentionally omits catch-clause parameters out of concern that a rethrow during the move would throw a stripped exception object. This should not be problematic in most cases, since exception objects are typically small.]
Date: 2010-08-03.00:00:00
N3092 comment DEĀ 11

It is unclear whether copy elision is permitted when returning a parameter of class type. If not, it should still be possible to move, rather than copy, the return value.

Suggested resolution: Amend paragraph 34 to explicitly exclude function parameters from copy elision. Amend paragraph 35 to include function parameters as eligible for move-construction.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetstatus: dr -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3190
2010-11-29 00:00:00adminsetstatus: tentatively ready -> dr
2010-10-18 00:00:00adminsetmessages: + msg2988
2010-10-18 00:00:00adminsetstatus: drafting -> tentatively ready
2010-08-03 00:00:00admincreate