diff --git a/include/stdexec/__detail/__transform_sender.hpp b/include/stdexec/__detail/__transform_sender.hpp index 406bd77b4..91086bf3f 100644 --- a/include/stdexec/__detail/__transform_sender.hpp +++ b/include/stdexec/__detail/__transform_sender.hpp @@ -88,9 +88,25 @@ namespace STDEXEC // is. A caller holding a new sender an earlier step returned by value // skips such a step, so that the sender can be returned without being // moved. + // + // (The tag's transformation is checked only when the domain's isn't: naming the concept + // would check it even where `&&` skips it, and checking it can instantiate the tag's + // default transformation, which a domain that transforms the sender replaces.) template - static constexpr bool __leaves_alone = __same_as<__domain_for_t<_Sndr, _Env>, default_domain> - && !__has_tag_transform_sender<_OpTag, _Sndr, _Env>; + static consteval auto __is_leaves_alone() noexcept -> bool + { + if constexpr (__same_as<__domain_for_t<_Sndr, _Env>, default_domain>) + { + return !__has_tag_transform_sender<_OpTag, _Sndr, _Env>; + } + else + { + return false; + } + } + + template + static constexpr bool __leaves_alone = __is_leaves_alone<_Sndr, _Env>(); template STDEXEC_ATTRIBUTE(nodiscard, host, device) @@ -237,6 +253,15 @@ namespace STDEXEC __detail::__transform_sender<__detail::__completing_domain_t, set_value_t>>; + // Does neither step transform the sender? Then transform_sender returns it as it is, + // without composing the steps. + template + static constexpr bool __leaves_alone = + __detail::__transform_sender<__detail::__starting_domain_t<_Env>, + start_t>::template __leaves_alone<_Sndr, _Env> + && __detail::__transform_sender<__detail::__completing_domain_t, + set_value_t>::template __leaves_alone<_Sndr, _Env>; + public: // NOT TO SPEC: template @@ -247,13 +272,24 @@ namespace STDEXEC return static_cast<_Sndr&&>(__sndr); } - template > + template + requires __leaves_alone<_Sndr, _Env> + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto operator()(_Sndr&& __sndr, _Env const &) const noexcept -> _Sndr&& + { + return static_cast<_Sndr&&>(__sndr); + } + + // (__impl_fn_t is named in the return type, not in a default template argument, which + // would be substituted before the constraint is checked.) + template + requires(!__leaves_alone<_Sndr, _Env>) STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) constexpr auto operator()(_Sndr&& __sndr, _Env const & __env) const - noexcept(__nothrow_callable<_ImplFn, _Sndr, _Env const &>) - -> __call_result_t<_ImplFn, _Sndr, _Env const &> + noexcept(__nothrow_callable<__impl_fn_t<_Sndr, _Env>, _Sndr, _Env const &>) + -> __call_result_t<__impl_fn_t<_Sndr, _Env>, _Sndr, _Env const &> { - return _ImplFn()(static_cast<_Sndr&&>(__sndr), __env); + return __impl_fn_t<_Sndr, _Env>()(static_cast<_Sndr&&>(__sndr), __env); } }; diff --git a/test/exec/test_timed_thread_scheduler.cpp b/test/exec/test_timed_thread_scheduler.cpp index 751647b3c..699622425 100644 --- a/test/exec/test_timed_thread_scheduler.cpp +++ b/test/exec/test_timed_thread_scheduler.cpp @@ -414,6 +414,12 @@ namespace } # if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L + // GCC 12 wrongly warns that connect's copy of the receiver's std::stop_token (in the + // environment it passes to transform_sender) can free the shared stop state before the + // receiver is moved. The receiver's own reference keeps the state alive. + STDEXEC_PRAGMA_PUSH() + STDEXEC_PRAGMA_IGNORE_GNU("-Wuse-after-free") + enum class completion { value, @@ -472,6 +478,8 @@ namespace REQUIRE(future.wait_for(std::chrono::seconds(10)) == std::future_status::ready); CHECK(future.get() == completion::stopped); } + + STDEXEC_PRAGMA_POP() # endif } // namespace #endif