Repository navigation
Conversation
`__promise_base::return_value(with_stopped)` took a non-template
`with_stopped` parameter. `with_stopped` is an empty aggregate, so `{}`
converts to it, and for any `_Ty` that `{}` only reaches through a
user-defined conversion (std::expected<void, E>, std::optional<U>,
std::string, ...) the value overload and the `with_stopped` overload are
indistinguishable. The non-template wins the tie, so `co_return {};`
silently completed the task with set_stopped instead of
value-initializing the result.
Make the `with_stopped` overload a template so a braced-init-list can't
deduce it, and make the two overloads mutually exclusive on a single
predicate so `co_return with_stopped{}` (and an lvalue `with_stopped`)
still stops the task, while a `_Ty` constructible from `with_stopped`
still receives it as an ordinary value.
Fixes NVIDIA#2472
ericniebler
approved these changes
Nov 23, 2026
Collaborator
|
/ok to test 31fd739 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey! This fixes #2472, where
co_return {};in atask<T>quietly completes the task withset_stoppedinstead of value-initializing the result.What was going on
__promise_basehad a non-templatereturn_value(with_stopped). Sincewith_stoppedis an empty aggregate,{}converts to it. For aTlikestd::expected<void, E>,std::optional<U>orstd::string,{}only reachesTthrough a user-defined conversion, so that overload and thereturn_value(_Value&&)template are equally good, and the tie-break goes to the non-template. (task<int>was never affected:{}->intis a standard conversion and wins outright.)I checked that this is the cause rather than just trusting the pattern: deleting only that overload in a scratch copy of the headers makes
co_return {}return a value for all of those types on GCC 15.2 and Clang 21.The fix
The
with_stoppedoverload is now a template, so a braced-init-list can't deduce it and{}goes to the value overload like it should. The two overloads are constrained on one shared predicate so they never compete, andco_return with_stopped{}/ an lvaluewith_stoppedstill stop the task.I deliberately did not use the simpler "value overload excludes
with_stopped" constraint from the issue. That would makeco_return with_stopped{}ill-formed for aTthat's constructible fromwith_stopped, which the existingstopped_as_valuetest covers. The predicate here keeps that case working: aTthat acceptswith_stoppedstill receives it as a plain value.I left
__promise_base<_Promise, void>alone. Itsreturn_valueisn't available on the compilers I could test with (co_return {}in atask<void>doesn't compile on GCC or Clang here), so I had no way to verify a change there.Testing
test_task.cppforco_return {}withstd::optional<int>andstd::string, plus one forco_returnof an lvaluewith_stopped.co_return {}test fails (sync_waitcomes back empty); with it, all the[task]tests pass on Clang 21 (40 cases) and GCC 15.2 (39 cases, one is compiled out on GCC), andtest_task_schedulerpasses on both.test_type_async_scopeandexamples/hello_corostill compile.