<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2672</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="2672"></A><H4>2672.
  
Lambda body SFINAE is still required, contrary to intent and note
</H4>
<B>Section: </B>13.10.3.1&#160; [<A href="https://wg21.link/temp.deduct.general">temp.deduct.general</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2022-09-30<BR>


<P>[Accepted as a DR at the November, 2023 meeting.]</P>

<P>Subclause 13.10.3.1 [<A href="https://wg21.link/temp.deduct.general#9">temp.deduct.general</A>] paragraph 9 specifies:</P>

<BLOCKQUOTE>

A <I>lambda-expression</I> appearing in a function type or a template
parameter is not considered part of the immediate context for the
purposes of template argument deduction.  [<I>Note 7:</I> The intent
is to avoid requiring implementations to deal with substitution
failure involving arbitrary statements. ... -- end note ]

</BLOCKQUOTE>

<P>However, the intent of the note is not satisfied by the normative
rule, because a <I>lambda-expression</I> appearing in
a <I>requires-expression</I> has the same concerns as one in a
function signature.</P>

<P>Suggested resolution: Change the rule to say that substitution into
the body of a lambda is never in the immediate context of substitution
into the lambda-expression and move the rule somewhere more
general.</P>

<P><U>Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:</U></P>

<OL>
<LI>
<P>Change in 13.5.2.3 [<A href="https://wg21.link/temp.constr.atomic#3">temp.constr.atomic</A>] paragraph 3 as follows:</P>

<BLOCKQUOTE>

To determine if an atomic constraint is satisfied, the parameter
mapping and template arguments are first substituted into its
expression. If substitution results in an invalid type or
expression <INS>in the immediate context of the atomic constraint
(13.10.3.1 [<A href="https://wg21.link/temp.deduct.general">temp.deduct.general</A>])</INS>, the constraint is not
satisfied. Otherwise, the lvalue-to-rvalue conversion
(7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]) is performed if necessary, and E shall be
a constant expression of type bool. The constraint is satisfied if and
only if evaluation of E results in true.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 13.10.3.1 [<A href="https://wg21.link/temp.deduct.general#9">temp.deduct.general</A>] paragraph 9 as follows:</P>

<BLOCKQUOTE>

<DEL>A <I>lambda-expression</I> appearing in a function type or a template
parameter</DEL>
<INS>Substituting into the body of a <I>lambda-expression</I></INS>
is <DEL>not considered part of</DEL> <INS>never in</INS> the immediate
context <DEL>for the purposes of template argument deduction</DEL>
<INS>of substitution into the <I>lambda-expression</I></INS>.
[<I>Note 7:</I> The intent is to avoid requiring implementations to
deal with substitution failure involving arbitrary statements.

</BLOCKQUOTE>
</LI>
</OL>

<P><B>Proposed resolution (approved by CWG 2023-11-09):</B></P>

<OL>

<LI>
<P>Change in 7.5.8.1 [<A href="https://wg21.link/expr.prim.req.general#5">expr.prim.req.general</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

The substitution of template arguments into
a <I>requires-expression</I> <DEL>may</DEL> <INS>can</INS> result in
the formation of invalid types or expressions in <INS>the immediate
context of</INS>
its <I>requirement</I>s <INS>(13.10.3.1 [<A href="https://wg21.link/temp.deduct.general">temp.deduct.general</A>])</INS> or
the violation of the semantic constraints of
those <I>requirement</I>s.  In such cases,
the <I>requires-expression</I> evaluates to false; it does not cause
the program to be ill-formed. The substitution and semantic constraint
checking proceeds in lexical order and stops when a condition that
determines the result of the <I>requires-expression</I> is
encountered. If substitution (if any) and semantic constraint checking
succeed, the <I>requires-expression</I> evaluates to true.

</BLOCKQUOTE>

</LI>

<LI>
<P>Change in 13.5.2.3 [<A href="https://wg21.link/temp.constr.atomic#3">temp.constr.atomic</A>] paragraph 3 as follows:</P>

<BLOCKQUOTE>

To determine if an atomic constraint is satisfied, the parameter
mapping and template arguments are first substituted into its
expression. If substitution results in an invalid type or
expression <INS>in the immediate context of the atomic constraint
(13.10.3.1 [<A href="https://wg21.link/temp.deduct.general">temp.deduct.general</A>])</INS>, the constraint is not
satisfied. Otherwise, the lvalue-to-rvalue conversion
(7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]) is performed if necessary, and E shall be
a constant expression of type bool. The constraint is satisfied if and
only if evaluation of E results in true.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 13.10.3.1 [<A href="https://wg21.link/temp.deduct.general#9">temp.deduct.general</A>] paragraph 9 as follows:</P>

<BLOCKQUOTE>

<DEL>A <I>lambda-expression</I> appearing in a function type or a template
parameter
is not considered part of the immediate
context for the purposes of template argument deduction</DEL>.
<INS>When substituting into a <I>lambda-expression</I>, substitution
into its body is not in the immediate context.</INS>
[<I>Note 7:</I> The intent is to avoid requiring implementations to
deal with substitution failure involving arbitrary statements.

</BLOCKQUOTE>
</LI>
</OL>

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