Skip to content

Commit c928472

Browse files
authored
Merge pull request NVIDIA#2168 from bjornpagen/fix/sync-wait-no-exceptions
sync_wait: terminate instead of misreporting errors as stopped when exceptions are unavailable
2 parents f4d9cdf + 256d4f5 commit c928472

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

include/stdexec/__detail/__sync_wait.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ namespace STDEXEC::__sync_wait
118118
template <class _Error>
119119
constexpr void set_error(_Error __err) noexcept
120120
{
121+
# if STDEXEC_NO_STDCPP_EXCEPTIONS()
122+
// sync_wait's only way to deliver an error to its caller is to rethrow
123+
// it. Without exception support, std::make_exception_ptr returns a null
124+
// exception_ptr, which the rethrow path would silently skip -- turning
125+
// an error completion into an empty optional, indistinguishable from a
126+
// stopped completion. Errors must not masquerade as cancellation:
127+
// terminate loudly instead.
128+
(void) __err;
129+
STDEXEC_TERMINATE();
130+
# else
121131
if constexpr (__same_as<_Error, std::exception_ptr>)
122132
{
123133
STDEXEC_ASSERT(__err != nullptr); // std::exception_ptr must not be null.
@@ -132,6 +142,7 @@ namespace STDEXEC::__sync_wait
132142
__state_->__eptr_ = std::make_exception_ptr(static_cast<_Error&&>(__err));
133143
}
134144
__state_->__loop_.finish();
145+
# endif
135146
}
136147

137148
constexpr void set_stopped() noexcept

0 commit comments

Comments
 (0)