|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4357" status="New"> |
| 5 | +<title><tt><i>connect-awaitable</i></tt> should use `is_void_v` to check for result-type of |
| 6 | +`co_await` expression instead of <tt>same_as<void></tt></title> |
| 7 | +<section> |
| 8 | +<sref ref="[exec.connect]"/> |
| 9 | +</section> |
| 10 | +<submitter>Lewis Baker</submitter> |
| 11 | +<date>27 Aug 2025</date> |
| 12 | +<priority>99</priority> |
| 13 | + |
| 14 | +<discussion> |
| 15 | +<p> |
| 16 | +The wording in <sref ref="[exec.connect]"/> p5 defines the <tt><i>connect-awaitable</i>()</tt> function as follows: |
| 17 | +</p> |
| 18 | +<blockquote><pre> |
| 19 | +<i>operation-state-task</i> <i>connect-awaitable</i>(DS sndr, DR rcvr) requires receiver_of<DR, Sigs> { |
| 20 | + exception_ptr ep; |
| 21 | + try { |
| 22 | + if constexpr (same_as<V, void>) { |
| 23 | + co_await std::move(sndr); |
| 24 | + co_await <i>suspend-complete</i>(set_value, std::move(rcvr)); |
| 25 | + } else { |
| 26 | + co_await <i>suspend-complete</i>(set_value, std::move(rcvr), co_await std::move(sndr)); |
| 27 | + } |
| 28 | + } catch(...) { |
| 29 | + ep = current_exception(); |
| 30 | + } |
| 31 | + co_await <i>suspend-complete</i>(set_error, std::move(rcvr), std::move(ep)); |
| 32 | +} |
| 33 | +</pre></blockquote> |
| 34 | +<p> |
| 35 | +The use of <tt>same_as<V, void></tt> in the if-constexpr condition does not cover the case where the |
| 36 | +result of the `co_await` expression has type <i>cv</i> `void`. It should use <tt>is_void_v<V></tt> |
| 37 | +instead to allow it to match all `void` types, not just unqualified `void`. |
| 38 | +</p> |
| 39 | + |
| 40 | +</discussion> |
| 41 | + |
| 42 | +<resolution> |
| 43 | +<p> |
| 44 | +This wording is relative to <paper num="N5014"/>. |
| 45 | +</p> |
| 46 | + |
| 47 | +<ol> |
| 48 | + |
| 49 | +<li><p>Modify <sref ref="[exec.connect]"/> as indicated:</p> |
| 50 | + |
| 51 | +<blockquote> |
| 52 | +<p> |
| 53 | +-5- Let `V` name the type <tt><i>await-result-type</i><DS, <i>connect-awaitable-promise</i>></tt>, |
| 54 | +let `Sigs` name the type |
| 55 | +</p> |
| 56 | +<blockquote><pre> |
| 57 | +completion_signatures< |
| 58 | + <i>SET-VALUE-SIG</i>(V), // <i>see <sref ref="[exec.snd.concepts]"/></i> |
| 59 | + set_error_t(exception_ptr), |
| 60 | + set_stopped_t()> |
| 61 | +</pre></blockquote> |
| 62 | +<p> |
| 63 | +and let <tt><i>connect-awaitable</i></tt> be an exposition-only coroutine defined as follows: |
| 64 | +</p> |
| 65 | +<blockquote><pre> |
| 66 | +namespace std::execution { |
| 67 | + […] |
| 68 | + <i>operation-state-task</i> <i>connect-awaitable</i>(DS sndr, DR rcvr) requires receiver_of<DR, Sigs> { |
| 69 | + exception_ptr ep; |
| 70 | + try { |
| 71 | + if constexpr (<del>same_as<V, void></del><ins>is_void_v<V></ins>) { |
| 72 | + co_await std::move(sndr); |
| 73 | + co_await <i>suspend-complete</i>(set_value, std::move(rcvr)); |
| 74 | + } else { |
| 75 | + co_await <i>suspend-complete</i>(set_value, std::move(rcvr), co_await std::move(sndr)); |
| 76 | + } |
| 77 | + } catch(...) { |
| 78 | + ep = current_exception(); |
| 79 | + } |
| 80 | + co_await <i>suspend-complete</i>(set_error, std::move(rcvr), std::move(ep)); |
| 81 | + } |
| 82 | +} |
| 83 | +</pre></blockquote> |
| 84 | +</blockquote> |
| 85 | + |
| 86 | +</li> |
| 87 | + |
| 88 | +</ol> |
| 89 | +</resolution> |
| 90 | + |
| 91 | +</issue> |
0 commit comments