From 19f6dcee4052c32553cdd1f9bb90c97af3b2915e Mon Sep 17 00:00:00 2001 From: Master Date: Wed, 25 Nov 2026 21:38:50 -0600 Subject: [PATCH 1/3] Fix pending async_scope future move assignment --- include/exec/async_scope.hpp | 12 +++- test/exec/CMakeLists.txt | 1 + .../test_spawn_future_move_assignment.cpp | 72 +++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test/exec/test_spawn_future_move_assignment.cpp diff --git a/include/exec/async_scope.hpp b/include/exec/async_scope.hpp index 65f5c5797..4838d265e 100644 --- a/include/exec/async_scope.hpp +++ b/include/exec/async_scope.hpp @@ -675,7 +675,17 @@ namespace experimental::execution using sender_concept = STDEXEC::sender_tag; __future(__future&&) = default; - auto operator=(__future&&) -> __future& = default; + auto operator=(__future&& __other) noexcept -> __future& + { + if (this != &__other) + { + // Apply the existing destructor's pending-state ownership transfer + // to the old future instead of deleting its unique_ptr directly. + __future __old{std::move(*this)}; + __state_ = std::move(__other.__state_); + } + return *this; + } ~__future() noexcept { diff --git a/test/exec/CMakeLists.txt b/test/exec/CMakeLists.txt index d83ea9c96..b9d470061 100644 --- a/test/exec/CMakeLists.txt +++ b/test/exec/CMakeLists.txt @@ -16,6 +16,7 @@ set(exec_test_sources ../test_main.cpp + test_spawn_future_move_assignment.cpp test_bwos_lifo_queue.cpp test_atomic_intrusive_queue.cpp test_any_sender.cpp diff --git a/test/exec/test_spawn_future_move_assignment.cpp b/test/exec/test_spawn_future_move_assignment.cpp new file mode 100644 index 000000000..1e04d776b --- /dev/null +++ b/test/exec/test_spawn_future_move_assignment.cpp @@ -0,0 +1,72 @@ +/* + * Licensed under the Apache License, Version 2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace regression_spawn_future_move_assignment +{ + // Public APIs only, unmodified production headers. Both futures have already + // started their schedule operations, which are still queued in the run_loop. + + int run_case(int argc, char** argv) + { + auto mode = argc > 1 ? std::string_view(argv[1]) : std::string_view("assign"); + exec::async_scope scope; + stdexec::run_loop loop; + auto task = stdexec::schedule(loop.get_scheduler()); + using future = decltype(scope.spawn_future(task)); + std::optional first{scope.spawn_future(task)}; + auto second = scope.spawn_future(task); + if (mode == "completed") + { + loop.finish(); + loop.run(); + } + if (mode == "drop") + first.reset(); + else + *first = std::move(second); + std::fputs("future replacement/drop returned; draining queued operations\n", stderr); + if (mode != "completed") + { + loop.finish(); + loop.run(); + } + stdexec::sync_wait(scope.on_empty()); + std::printf("PASS mode=%.*s scope drained\n", int(mode.size()), mode.data()); + return 0; + } + +} // namespace regression_spawn_future_move_assignment + +TEST_CASE("spawn_future_move_assignment: assign", "[regression][async-scope-future]") +{ + char program[] = "regression"; + char arg0[] = "assign"; + char* argv[] = {program, arg0}; + REQUIRE(regression_spawn_future_move_assignment::run_case(2, argv) == 0); +} + +TEST_CASE("spawn_future_move_assignment: drop", "[regression][async-scope-future]") +{ + char program[] = "regression"; + char arg0[] = "drop"; + char* argv[] = {program, arg0}; + REQUIRE(regression_spawn_future_move_assignment::run_case(2, argv) == 0); +} + +TEST_CASE("spawn_future_move_assignment: completed", "[regression][async-scope-future]") +{ + char program[] = "regression"; + char arg0[] = "completed"; + char* argv[] = {program, arg0}; + REQUIRE(regression_spawn_future_move_assignment::run_case(2, argv) == 0); +} From aeeeffac9646f61be5f6be63fd73e7548fb84e51 Mon Sep 17 00:00:00 2001 From: Waterpine Date: Wed, 25 Nov 2026 21:46:13 -0600 Subject: [PATCH 2/3] Fix clang-format alignment in async_scope future --- include/exec/async_scope.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/async_scope.hpp b/include/exec/async_scope.hpp index 4838d265e..10deb398b 100644 --- a/include/exec/async_scope.hpp +++ b/include/exec/async_scope.hpp @@ -674,7 +674,7 @@ namespace experimental::execution public: using sender_concept = STDEXEC::sender_tag; - __future(__future&&) = default; + __future(__future&&) = default; auto operator=(__future&& __other) noexcept -> __future& { if (this != &__other) From 9504289d310db444ca545c923e69e3789706777a Mon Sep 17 00:00:00 2001 From: Waterpine Date: Wed, 25 Nov 2026 20:53:03 -0800 Subject: [PATCH 3/3] Use STDEXEC:: namespace macro in regression test nvc++ >= 26.3 configures stdexec into std::execution, so the stdexec:: namespace does not exist in the GPU CI builds. Use the STDEXEC macro like the rest of the test suite. Co-Authored-By: Claude Opus 5.5 --- test/exec/test_spawn_future_move_assignment.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/exec/test_spawn_future_move_assignment.cpp b/test/exec/test_spawn_future_move_assignment.cpp index 1e04d776b..c2da72acc 100644 --- a/test/exec/test_spawn_future_move_assignment.cpp +++ b/test/exec/test_spawn_future_move_assignment.cpp @@ -20,8 +20,8 @@ namespace regression_spawn_future_move_assignment { auto mode = argc > 1 ? std::string_view(argv[1]) : std::string_view("assign"); exec::async_scope scope; - stdexec::run_loop loop; - auto task = stdexec::schedule(loop.get_scheduler()); + STDEXEC::run_loop loop; + auto task = STDEXEC::schedule(loop.get_scheduler()); using future = decltype(scope.spawn_future(task)); std::optional first{scope.spawn_future(task)}; auto second = scope.spawn_future(task); @@ -40,7 +40,7 @@ namespace regression_spawn_future_move_assignment loop.finish(); loop.run(); } - stdexec::sync_wait(scope.on_empty()); + STDEXEC::sync_wait(scope.on_empty()); std::printf("PASS mode=%.*s scope drained\n", int(mode.size()), mode.data()); return 0; }