Date: Sun, 11 Oct 2020 16:39:53 +0300
The standard says ([dcl.fct.def.coroutine]):
6 The unqualified-ids return_void and return_value are looked up in
the scope of the promise type. If both are found, the program is ill-formed.
However, there are good reasons to want both:
std::future<void> yet_another();
std::future<void> my_coroutine() {
if (some_check) {
co_return; // calls promise_type::return_void()
}
co_await something_else();
co_return yet_another(); // calls
promise_type::return_value(std::future<void>)
}
The last statement calls another coroutine, but this is not legal under
the current wording (though gcc accepts it).
I could rewrite the coroutine as follows:
std::future<void> my_coroutine() {
if (some_check) {
co_return; // calls promise_type::return_void()
}
co_await something_else();
co_await yet_another(); // typically suspends the coroutine here
co_return; // optional
}
But this will cost something - typically the coroutine body has to be
suspended and awakened for co_await.
Remediation: allow return_value() and return_void() to coexist.
6 The unqualified-ids return_void and return_value are looked up in
the scope of the promise type. If both are found, the program is ill-formed.
However, there are good reasons to want both:
std::future<void> yet_another();
std::future<void> my_coroutine() {
if (some_check) {
co_return; // calls promise_type::return_void()
}
co_await something_else();
co_return yet_another(); // calls
promise_type::return_value(std::future<void>)
}
The last statement calls another coroutine, but this is not legal under
the current wording (though gcc accepts it).
I could rewrite the coroutine as follows:
std::future<void> my_coroutine() {
if (some_check) {
co_return; // calls promise_type::return_void()
}
co_await something_else();
co_await yet_another(); // typically suspends the coroutine here
co_return; // optional
}
But this will cost something - typically the coroutine body has to be
suspended and awakened for co_await.
Remediation: allow return_value() and return_void() to coexist.
Received on 2020-10-11 08:39:59