<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2095</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="2095"></A><H4>2095.
  
Capturing rvalue references to functions by copy
</H4>
<B>Section: </B>7.5.6.3&#160; [<A href="https://wg21.link/expr.prim.lambda.capture">expr.prim.lambda.capture</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>Hubert Tong
 &#160;&#160;&#160;

 <B>Date: </B>2015-03-07<BR>


<P>[Adopted at the February, 2016 meeting.]</P>



<P>According to 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#15">expr.prim.lambda</A>] paragraph 15,</P>

<BLOCKQUOTE>

An entity is captured by copy if it is implicitly captured
and the <I>capture-default</I> is <TT>=</TT> or if it is explicitly
captured with a capture that is not of the form &amp;
<I>identifier</I> or
&amp; <I>identifier</I> <I>initializer</I>. For each entity
captured by copy, an unnamed non-static data member is
declared in the closure type. The declaration order of these
members is unspecified. The type of such a data member is
the type of the corresponding captured entity if the entity
is not a reference to an object, or the referenced type
otherwise.

</BLOCKQUOTE>

<P>It's not clear how to handle capture by copy when the
entity is an rvalue reference to function.  In particular,
this appears to be a contradiction with 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#3">expr.prim.lambda</A>] paragraph 3,
</P>

<BLOCKQUOTE>

An implementation shall not add members of rvalue reference
type to the closure type.

</BLOCKQUOTE>

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

<P>Change 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#15">expr.prim.lambda</A>] paragraph 15 as follows:</P>

<BLOCKQUOTE>

An entity is <I>captured by copy</I> if it is implicitly captured and
the <I>capture-default</I> is <TT>=</TT> or if it is explicitly captured
with a capture that is not of the form <TT>&amp;</TT> <I>identifier</I> or
<TT>&amp;</TT> <I>identifier initializer</I>. For each entity captured by
copy, an unnamed non-static data member is declared in the closure
type. The declaration order of these members is unspecified. The type of
such a data member is <INS>the referenced type if the entity is a reference
to an object, an lvalue reference to the referenced function type if the
entity is a reference to a function, or</INS> the type of the corresponding
captured entity <DEL>if the entity is not a reference to an object, or the
referenced type</DEL> otherwise. <DEL>[<I>Note:</I> If the captured entity
is a reference to a function, the corresponding data member is also a
reference to a function.  &#8212;<I>end note</I>]</DEL> A member of an
anonymous union shall not be captured by copy.

</BLOCKQUOTE>

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