Commit 8bb5b46
committed
asioexec::completion_token: Conversion & Dangling References
Asio operations declare a set of completion signatures but may send
different, convertible arguments upon completion. This is overwhelmingly
(exclusively?) observed with differing value categories: An operation
declares std::error_code but actually sends const std::error_code&.
As originally added (35a3e31)
asioexec::completion_token works around the above by pre-converting the
arguments provided to the Asio completion handler. This ensures that the
correct type with the correct cv- and ref-qualification is provided when
sending the completion signal and also was intended to ensure that no
operation which would be performed within stdexec::set_value is liable
to throw an exception (i.e. performing a conversion which is not
noexcept).
The implementation-detail function used to provide the above-mentioned
pre-conversion is asioexec::detail::completion_token::convert which has
two overloads with the following intentions:
- One which may change the cv- and ref-qualification but otherwise
performs no actions (and is therefore marked noexcept), and
- One which may perform any conversion (and is therefore not marked
noexcept)
Unfortunately as originally implemented the former overload was
constrained on std::is_convertible_v which permits conversions beyond
changing cv- and ref-qualification. Combined with the fact that the
former overload returns a reference (since it's similar to std::forward)
this meant that the function could:
- Throw internally (thereby calling std::terminate as it is marked
noexcept), and
- Return a dangling reference (since a prvalue could be synthesized to
effect the required conversion)
Added reproducing tests and updated the constraints on the former
overload so that it is only a candidate when the involved conversions
involve changing cv- and ref-qualification (and therefore involve no
potentially-throwing operations and cannot produce dangling references).1 parent cb00893 commit 8bb5b46
2 files changed
Lines changed: 38 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
73 | 99 | | |
74 | 100 | | |
75 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
| |||
0 commit comments