From 7123c5808cce2339515f7efece4e0640112bcd31 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 14 Dec 2023 13:25:29 -0800 Subject: [PATCH] fix an exception safety bug in schedule_from --- include/stdexec/execution.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/stdexec/execution.hpp b/include/stdexec/execution.hpp index 9acb81368..f195f5dab 100644 --- a/include/stdexec/execution.hpp +++ b/include/stdexec/execution.hpp @@ -4272,9 +4272,6 @@ namespace stdexec { : __data_() , __state2_(connect(schedule(__sched), __receiver2_t{this})) { } - - void __complete() noexcept { - } }; struct schedule_from_t { @@ -4324,7 +4321,16 @@ namespace stdexec { // we can forward the completion from within the scheduler's // execution context. using __async_result = __decayed_tuple<_Tag, _Args...>; - __state.__data_.template emplace<__async_result>(_Tag(), (_Args&&) __args...); + if constexpr (__nothrow_constructible_from<__async_result, _Tag, _Args...>) { + __state.__data_.template emplace<__async_result>(_Tag(), (_Args&&) __args...); + } else { + try { + __state.__data_.template emplace<__async_result>(_Tag(), (_Args&&) __args...); + } catch(...) { + set_error(std::move(__rcvr), std::current_exception()); + return; + } + } // Enqueue the schedule operation so the completion happens // on the scheduler's execution context. stdexec::start(__state.__state2_);