<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1148</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1148"></A><H4>1148.
  
Copy elision and move construction of function parameters
</H4>
<B>Section: </B>11.9.6&#160; [<A href="https://wg21.link/class.copy.elision">class.copy.elision</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++11
 &#160;&#160;&#160;

 <B>Submitter: </B>DE
 &#160;&#160;&#160;

 <B>Date: </B>2010-08-03<BR><BR>


<P>[Voted into the WP at the November, 2010 meeting.]</P>

<A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3296.html#DE11">N3092 comment
  DE&#160;11<BR></A>

<P>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.</P>

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

<P><B>Proposed resolution (September, 2010):</B></P>

<OL>
<LI><P>Change 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#34">class.copy.ctor</A>] paragraph 34 bullets 1 and 2
as follows:</P></LI>

<UL>
<LI><P>in a <TT>return</TT> statement in a function with a class
return type, when the expression is the name of a non-volatile
automatic object <INS>(other than a function or catch-clause
parameter)</INS> 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</P></LI>

<LI><P>in a <I>throw-expression</I>, when the operand is the name of a
non-volatile automatic object <INS>(other than a function or
catch-clause parameter)</INS> whose scope does not extend beyond the
end of the innermost enclosing <I>try-block</I> (if there is one), the
copy/move operation from the operand to the exception object
(14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]) can be omitted by constructing the
automatic object directly into the exception object</P></LI>

</UL>

<P>Change 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#35">class.copy.ctor</A>] paragraph 35 as follows:</P>

<BLOCKQUOTE>

When the criteria for elision of a copy operation are met<INS>, or
would be met save for the fact that the source object is a function
parameter,</INS> and the object to be copied is designated by an
lvalue, overload resolution...

</BLOCKQUOTE>

</OL>

<I>[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.]</I>

<BR><BR>
</BODY>
</HTML>
