<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1249</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="1249"></A><H4>1249.
  
Cv-qualification of nested lambda capture
</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>CD6
 &#160;&#160;&#160;

 <B>Submitter: </B>James Widman
 &#160;&#160;&#160;

 <B>Date: </B>2011-03-02<BR>


<P>[Accepted as a DR at the October, 2021 meeting.]</P>

<P>Consider the following example:</P>

<PRE>
    void f(int i) {
      auto l1 = [i] {
        auto l2 = [&amp;i] {
          ++i;    // Well-formed?
        };
      };
    }
</PRE>

<P>Because the <TT>l1</TT> lambda is not marked as <TT>mutable</TT>,
its <TT>operator()</TT> is <TT>const</TT>; however, it is not clear from
the wording of 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#16">expr.prim.lambda</A>] paragraph 16 whether the
captured member of the enclosing lambda is considered <TT>const</TT> or
not.</P>

<P><B>Proposed resolution (August, 2021):</B></P>

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

<BLOCKQUOTE>

<P>If a <I>lambda-expression</I> <TT>m2</TT> captures an
entity and that entity is captured by an immediately
enclosing <I>lambda-expression</I> <TT>m1</TT>,
then <TT>m2</TT>'s capture is transformed as follows:</P>

<UL>
<LI><P>
<DEL>if</DEL> <INS>If</INS> <TT>m1</TT> captures
the entity by copy, <TT>m2</TT> captures the corresponding
non-static data member of <TT>m1</TT>'s closure
type; <INS>if <TT>m1</TT> is not <TT>mutable</TT>, the
non-static data member is considered to be
const-qualified.</INS>
</P></LI>

<LI><P>
<DEL>if</DEL> <INS>If</INS> <TT>m1</TT> captures the
entity by reference, <TT>m2</TT> captures the same entity
captured by <TT>m1</TT>.</P></LI>

</UL>

</BLOCKQUOTE>

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