Return by converting move constructor
_N4750_.15.8 [class.copy]
Jeffrey Yasskin

Created on 2012-10-23.00:00:00 last changed 75 months ago


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 _N4750_.15.8 [class.copy] paragraph 32 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, or when the expression in a return statement is a (possibly parenthesized) id-expression that names an object with automatic storage duration declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If overload resolution fails...
Date: 2013-09-15.00:00:00

Additional note (September, 2013):

Returned to "open" status in light of CD National Body comment.

Date: 2013-04-15.00:00:00

Rationale (April, 2013):

CWG felt that this suggestion should be considered in a broader context and was thus more appropriate for EWG.

Date: 2013-10-14.00:00:00
N3690 comment USĀ 13

Currently the conditions for moving from an object returned from a function are tied closely to the criteria for copy elision, which requires that the type of the object being returned be the same as the return type of the function. Another possibility that should be considered is to allow something like

  optional<T> foo() {
    T t;
    return t;

and allow optional<T>::optional(T&&) to be used for the initialization of the return type. Currently this can be achieved explicitly by use of std::move, but it would be nice not to have to remember to do so.

Similarly, the current rules apply only to complete objects; it could make sense to allow moving from subobjects of local objects.

(See also issue 1493 for other questions about the criteria for moving from a returned object.)

Date User Action Args
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: + msg4960
2014-03-03 00:00:00adminsetstatus: ready -> dr
2013-10-14 00:00:00adminsetmessages: + msg4600
2013-10-14 00:00:00adminsetmessages: + msg4599
2013-10-14 00:00:00adminsetstatus: extension -> ready
2013-05-03 00:00:00adminsetmessages: + msg4446
2013-05-03 00:00:00adminsetstatus: open -> extension
2012-10-23 00:00:00admincreate