|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4339" status="New"> |
| 5 | +<title><code>task</code>'s coroutine frame may be released late</title> |
| 6 | +<section><sref ref="[exec.task]"/></section> |
| 7 | +<submitter>Dietmar Kühl</submitter> |
| 8 | +<date>31 Aug 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +The specification of <code>task</code> doesn't spell out when the |
| 14 | +coroutine frame is destroyed (i.e., when <code>handle.destroy()</code> |
| 15 | +is called). As a result the lifetime of arguments passed to the |
| 16 | +coroutine and/or of local variables in the coroutine body may be |
| 17 | +longer than expected. |
| 18 | +</p> |
| 19 | +<p> |
| 20 | +The intention is that the coroutine frame is destroyed before any |
| 21 | +of the completion functions is called. One implication of this |
| 22 | +requirement is that the result and error objects can't be stored |
| 23 | +in the <code>promise_type</code> when the completion function is |
| 24 | +called although the exposition-only members <code><i>result</i></code> |
| 25 | +and <code><i>errors</i></code> imply exactly that. Instead the data |
| 26 | +needs to be stored in the operation state object or it needs to be |
| 27 | +moved to a different place before calling <code>destroy()</code>. |
| 28 | +</p> |
| 29 | +<p> |
| 30 | +The proposed resolution is to add a paragraph to the specification |
| 31 | +of <code>promise_type</code> in <sref ref="[task.promise]"/> that spells |
| 32 | +out that the coroutine frame is destroyed before any of the completion |
| 33 | +functions is called. To actually do that the exposition-only members |
| 34 | +<code><i>result</i></code> and <code><i>errors</i></code> can't |
| 35 | +remain as members of the <code>promise_type</code>. While writing |
| 36 | +the relevant change it turned out that <code><i>errors</i></code> |
| 37 | +is a <code>variant</code> which only ever stores an |
| 38 | +<code>exception_ptr</code> (the other potential errors are immediately |
| 39 | +reported via the awaiter return from <code>yield_value</code>). |
| 40 | +Thus, the <code>variant</code> can be replaced with an |
| 41 | +<code>exception_ptr</code>. |
| 42 | +</p> |
| 43 | +</discussion> |
| 44 | + |
| 45 | +<resolution> |
| 46 | +<p> |
| 47 | +</p> |
| 48 | +</resolution> |
| 49 | + |
| 50 | +</issue> |
0 commit comments