<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4203: Constraints on get-state functions are incorrect</title>
<meta property="og:title" content="Issue 4203: Constraints on get-state functions are incorrect">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4203.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#WP">WP</a> status.</em></p>
<h3 id="4203"><a href="lwg-defects.html#4203">4203</a>. Constraints on <i><code class='backtick'>get-state</code></i> functions are incorrect</h3>
<p><b>Section:</b> 33.9.12.7 <a href="https://wg21.link/exec.schedule.from">[exec.schedule.from]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Eric Niebler <b>Opened:</b> 2025-02-03 <b>Last modified:</b> 2025-06-23</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#exec.schedule.from">issues</a> in [exec.schedule.from].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Imported from:
<a href="https://github.com/cplusplus/sender-receiver/issues/313">cplusplus/sender-receiver #313</a>
and
<a href="https://github.com/cplusplus/sender-receiver/issues/314">cplusplus/sender-receiver #314</a>.
</p>
<p>
33.9.12.7 <a href="https://wg21.link/exec.schedule.from">[exec.schedule.from]</a> p6 reads:

<blockquote>
The member <code><i>impls-for</i>&lt;schedule_from_t&gt;::get-state</code>
is initialized with a callable object equivalent to the following lambda:
<pre><code>  []&lt;class Sndr, class Rcvr&gt;(Sndr&amp;&amp; sndr, Rcvr&amp; rcvr) noexcept(<i>see below</i>)
     requires sender_in&lt;<i>child-type</i>&lt;Sndr&gt;, env_of_t&lt;Rcvr&gt;&gt; {
</code></pre>
</blockquote>

The constraint should account for the fact that the child sender will
be connected with <code><i>FWD-ENV</i>(get_env(rcvr))</code>.
</p>

<p><i>[
The resolution touches some of the same text as LWG <a href="lwg-defects.html#4198" title="schedule_from isn't starting the schedule sender if decay-copying results throws (Status: WP)">4198</a><sup><a href="https://cplusplus.github.io/LWG/issue4198" title="Latest snapshot">(i)</a></sup>,
but without conflicting.
]</i></p>


<p>
Imported from:
<a href="https://github.com/cplusplus/sender-receiver/issues/315">cplusplus/sender-receiver #315</a>.
</p>
<p>
33.9.12.12 <a href="https://wg21.link/exec.when.all">[exec.when.all]</a> p6 reads:

<blockquote>
The member <code>impls-for&lt;when_all_t&gt;::<i>get-env</i></code>
is initialized with a callable object equivalent to the following lambda
expression:
<pre><code>  []&lt;class State, class Rcvr&gt;(auto&amp;&amp;, State&amp; state, const Receiver&amp; rcvr) noexcept {
    return <i>see below</i>;
  }
</code></pre>
Returns an object <code class='backtick'>e</code> such that
<ol style="list-style-type:none">
<li>(6.1) &mdash; <code class='backtick'>decltype(e)</code> models <i><code class='backtick'>queryable</code></i>, and</li>
<li>(6.2) &mdash; <code class='backtick'>e.query(get_stop_token)</code> is expression-equivalent to
<code>state.<i>stop-src</i>.get_token()</code>, and</li>
<li>(6.3) &mdash;
given a query object <code class='backtick'>q</code> with type other than <i>cv</i> <code class='backtick'>stop_token_t</code>,
<code class='backtick'>e.query(q)</code> is expression-equivalent to <code class='backtick'>get_env(rcvr).query(q)</code>.
</li>
</ol>
</blockquote>

The problem is in (6.3). It should be forwarding on <i><code class='backtick'>forwarding-query</code></i>'s
to <code class='backtick'>get_env(rcvr)</code> but is is instead forwarding all queries.
</p>

<p>
Imported from:
<a href="https://github.com/cplusplus/sender-receiver/issues/316">cplusplus/sender-receiver #316</a>.
</p>
<p>
The child senders should only see the parent's queries if they are forwarding queries.
</p>

<p>
Imported from:
<a href="https://github.com/cplusplus/sender-receiver/issues/311">cplusplus/sender-receiver #311</a>.
</p>

<p>
33.9.12.14 <a href="https://wg21.link/exec.stopped.opt">[exec.stopped.opt]</a>/para 3 reads:

<blockquote>
Let <code class='backtick'>sndr</code> and <code class='backtick'>env</code> be subexpressions such that <code class='backtick'>Sndr</code> is <code class='backtick'>decltype((sndr))</code>
and <code class='backtick'>Env</code> is <code class='backtick'>decltype((env))</code>.
If <code><i>sender-for</i>&lt;Sndr, stopped_as_optional_t&gt;</code> is <code class='backtick'>false</code>,
or if the type <code><i>single-sender-value-type</i>&lt;Sndr, Env&gt;</code>
is ill-formed or <code class='backtick'>void</code>,
then the expression <code class='backtick'>stopped_as_optional.transform_sender(sndr, env)</code>
is ill-formed; otherwise, it is equivalent to:
</blockquote>
the test for <code>single-sender-value-type&lt;Sndr, Env&gt;</code> is incorrect.
It should be testing its child for single-sender-ness.
</p>
<p>
In addition, it should be applying <i><code class='backtick'>FWD-ENV-T</code></i> to <code class='backtick'>Env</code>
so that only forwarding queries are forwarded.
</p>


<p><i>[2025-02-07; Reflector poll]</i></p>

<p>
Set priority to 1 after reflector poll.
</p>

<p><i>[Hagenberg 2025-02-11; move to Ready]</i></p>


<p><i>[Sofia 2025-06-21; Status changed: Voting &rarr; WP.]</i></p>



<p id="res-4203"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N5001" title=" Working Draft, Programming Languages — C++">N5001</a>.
</p>

<ol>
<li>
Change 33.9.2 <a href="https://wg21.link/exec.snd.expos">[exec.snd.expos]</a> as indicated:

<blockquote>
-2-
For a queryable object <code class='backtick'>env</code>,
<code><i>FWD-ENV</i>(env)</code> is an expression whose
type satisfies <i><code class='backtick'>queryable</code></i> such that for a query object <code class='backtick'>q</code>
and a pack of subexpressions <code class='backtick'>as</code>,
the expression <code><i>FWD-ENV</i>(env).query(q, as...)</code>
is ill-formed if <code class='backtick'>forwarding_query(q)</code> is <code class='backtick'>false</code>;
otherwise, it is expression-equivalent to <code class='backtick'>env.query(q, as...)</code>.
<ins>
The type <code><i>FWD-ENV-T</i>(Env)</code> is
<code>decltype(<i>FWD-ENV</i>(declval&lt;Env&gt;()))</code>.
</ins>
</blockquote>
</li>

<li>
Change 33.9.12.7 <a href="https://wg21.link/exec.schedule.from">[exec.schedule.from]</a> as indicated:

<blockquote>
-6-
The member
<code><i>impls-for</i>&lt;schedule_from_t&gt;::<i>get-state</i></code>
is initialized with a callable object equivalent to the following lambda:
<pre><code>  []&lt;class Sndr, class Rcvr&gt;(Sndr&amp;&amp; sndr, Rcvr&amp; rcvr) noexcept(<i>see below</i>)
   requires sender_in&lt;child-type&lt;Sndr&gt;, <ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>&gt; {
</code></pre>
<p>&hellip;</p>
<p>
-8-
Let <code class='backtick'>Sigs</code> be a pack of the arguments to the <code class='backtick'>completion_signatures</code>
specialization named by
<code>completion_signatures_of_t&lt;child-type&lt;Sndr&gt;,
  <ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>&gt;</code>.
Let <code><i>as-tuple</i></code>
be an alias template that transforms a completion signature
<code>Tag(Args...)</code> into the tuple specialization
<code><i>decayed-tuple</i>&lt;Tag, Args...&gt;</code>.
Then <code>variant_t</code> denotes the type
<code>variant&lt;monostate, as-tuple&lt;Sigs&gt;...&gt;</code>,
except with duplicate types removed.
</p>
</blockquote>
</li>

<li>
Change 33.9.12.10 <a href="https://wg21.link/exec.let">[exec.let]</a> as indicated:

<blockquote>
<p>
-6-
Let <i><code class='backtick'>receiver2</code></i> denote the following exposition-only class template:
<pre><code>  namespace std::execution {
    &hellip;
  }
</code></pre>
Invocation of the function <code><i>receiver2</i>::get_env</code>
returns an object <code class='backtick'>e</code> such that
<ol style="list-style-type:none">
<li>(6.1) &mdash;
<code class='backtick'>decltype(e)</code> models <i><code class='backtick'>queryable</code></i> and
</li>
<li>(6.2) &mdash;
given a query object <code class='backtick'>q</code>, the expression <code class='backtick'>e.query(q)</code> is expression-equivalent
to
<code><i>env</i>.query(q)</code>
if that expression is valid<del>,</del><ins>;</ins>
otherwise,
<ins>if the type of <code class='backtick'>q</code> satisfies <i><code class='backtick'>forwarding-query</code></i>,</ins>
<code class='backtick'>e.query(q)</code> is expression-equivalent to
<code>get_env(<i>rcvr</i>).query(q)</code>
<ins>; otherwise, <code class='backtick'>e.query(q)</code> is ill-formed</ins>.
</li>
</ol>
</p>
<p>
-7-
<code><i>impls-for</i>&lt;<i>decayed-typeof</i>&lt;<i>let-cpo</i>&gt;&gt;::<i>get-state</i></code>
is initialized with a callable object [&hellip;]
</p>
<p>
-8-
Let <code class='backtick'>Sigs</code> be a pack of the arguments to the <code class='backtick'>completion_signatures</code>
specialization named by
<code>completion_signatures_of_t&lt;<i>child-type</i>&lt;Sndr&gt;,
<ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>&gt;</code>.
Let <code class='backtick'>LetSigs</code> be a pack of those types in <code class='backtick'>Sigs</code> with a return type of
<code><i>decayed-typeof</i>&lt;<i>set-cpo</i>&gt;</code>.
Let <code class='backtick'>as-tuple</code> be an alias template such that
<code><i>as-tuple</i>&lt;Tag(Args...)&gt;</code>
denotes the type <code><i>decayed-tuple</i>&lt;Args...&gt;</code>.
Then <code class='backtick'>args_variant_t</code> denotes the type
<code>variant&lt;monostate, <i>as-tuple</i>&lt;LetSigs&gt;...&gt;</code>
except with duplicate types removed.
</p>
</blockquote>
</li>

<li>
Change 33.9.12.12 <a href="https://wg21.link/exec.when.all">[exec.when.all]</a> as indicated:

<blockquote>
<p>
-6-
The member <code>impls-for&lt;when_all_t&gt;::<i>get-env</i></code>
is initialized with a callable object equivalent to the following lambda
expression:
<pre><code>  []&lt;class State, class Rcvr&gt;(auto&amp;&amp;, State&amp; state, const Receiver&amp; rcvr) noexcept {
    return <i>see below</i>;
  }
</code></pre>
Returns an object <code class='backtick'>e</code> such that
<ol style="list-style-type:none">
<li>(6.1) &mdash; <code class='backtick'>decltype(e)</code> models <i><code class='backtick'>queryable</code></i>, and</li>
<li>(6.2) &mdash; <code class='backtick'>e.query(get_stop_token)</code> is expression-equivalent to
<code>state.<i>stop-src</i>.get_token()</code>, and</li>
<li>(6.3) &mdash;
given a query object <code class='backtick'>q</code> with type other than <i>cv</i> <code class='backtick'>stop_token_t</code>
<ins>and whose type satisfies <i><code class='backtick'>forwarding-query</code></i></ins>,
<code class='backtick'>e.query(q)</code> is expression-equivalent to <code class='backtick'>get_env(rcvr).query(q)</code>.
</li>
</ol>
</p>
<p>
-7-
The member <code><i>impls-for</i>&lt;when_all_t&gt;::<i>get-state</i></code>
is initialized with a callable object equivalent to the following
lambda expression:
<pre><code>  []&lt;class Sndr, class Rcvr&gt;(Sndr&amp;&amp; sndr, Rcvr&amp; rcvr) noexcept(e) -&gt; decltype(e) {
    return <i>e</i>;
  }
</code></pre>
where <i>e</i> is the expression
<pre><code>  std::forward&lt;Sndr&gt;(sndr).apply(<i>make-state</i>&lt;Rcvr&gt;())
</code></pre>
and <i><code class='backtick'>make-state</code></i> is the following exposition-only class template:
<pre><code>  template&lt;class Sndr, class Env&gt;
  concept max-1-sender-in = sender_in&lt;Sndr, Env&gt; &amp;&amp; <i>// exposition only</i>
    (tuple_size_v&lt;value_types_of_t&lt;Sndr, Env, tuple, tuple&gt;&gt; &lt;= 1);

  enum class <i>disposition</i> { <i>started</i>, <i>error</i>, <i>stopped</i> }; <i>// exposition only</i>

  template&lt;class Rcvr&gt;
  struct make-state {
   template&lt;max-1-sender-in&lt;<ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>&gt;... Sndrs&gt;
</code></pre>
&hellip;
</p>
<p>
-8- Let <i><code class='backtick'>copy_fail</code></i> be <code class='backtick'>exception_ptr</code> if [&hellip;]
</p>
<p>
-9-
The alias <code class='backtick'>values_tuple</code> denotes the type
<pre><code>  tuple&lt;value_types_of_t&lt;Sndrs, <ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>, <i>decayed-tuple</i>, optional&gt;...&gt;
</code></pre>
if that type is well-formed; otherwise, <code>tuple&lt;&gt;</code>.
</p>
</blockquote>
</li>

<li>
Change 33.9.12.13 <a href="https://wg21.link/exec.into.variant">[exec.into.variant]</a> as indicated:

<blockquote>
-5-
The member <code>impls-for&lt;into_variant_t&gt;::<i>get-state</i></code>
is initialized with a callable object equivalent to the following lambda:
<pre><code>  []&lt;class Sndr, class Rcvr&gt;(Sndr&amp;&amp; sndr, Rcvr&amp; rcvr) noexcept
    -&gt; type_identity&lt;value_types_of_t&lt;<i>child-type</i>&lt;Sndr&gt;, <ins><i>FWD-ENV-T</i>(</ins>env_of_t&lt;Rcvr&gt;<ins>)</ins>&gt;&gt; {
    return {};
  }
</code></pre>
</blockquote>
</li>

<li>
Change 33.9.12.14 <a href="https://wg21.link/exec.stopped.opt">[exec.stopped.opt]</a> as indicated:

<blockquote>
-3-
Let <code class='backtick'>sndr</code> and <code class='backtick'>env</code> be subexpressions such that <code class='backtick'>Sndr</code> is <code class='backtick'>decltype((sndr))</code>
and <code class='backtick'>Env</code> is <code class='backtick'>decltype((env))</code>.
If <code><i>sender-for</i>&lt;Sndr, stopped_as_optional_t&gt;</code> is <code class='backtick'>false</code>,
or if the type <code><i>single-sender-value-type</i>&lt;<ins><i>child-type</i>&lt;</ins>Sndr<ins>&gt;</ins>, <ins><i>FWD-ENV-T</i>(</ins>Env<ins>)</ins>&gt;</code>
is ill-formed or <code class='backtick'>void</code>,
then the expression <code class='backtick'>stopped_as_optional.transform_sender(sndr, env)</code>
is ill-formed; otherwise, it is equivalent to:
<pre><code>  auto&amp;&amp; [_, _, child] = sndr;
  using V = <i>single-sender-value-type</i>&lt;<ins><i>child-type</i>&lt;</ins>Sndr<ins>&gt;</ins>, <ins><i>FWD-ENV-T</i>(</ins>Env<ins>)</ins>&gt;;
</code></pre>
&hellip;
</blockquote>
</li>

</ol>






</body>
</html>
