Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix forwarding of return type from execution::then callable #994

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ namespace pika::cuda::experimental {
// Certain versions of GCC with optimizations fail on
// the move with an internal compiler error.
#if defined(PIKA_GCC_VERSION) && (PIKA_GCC_VERSION < 100000)
auto&& result = PIKA_INVOKE(std::move(r.f), PIKA_FORWARD(Ts, ts)...);
pika::execution::experimental::set_value(PIKA_MOVE(r.receiver),
PIKA_INVOKE(std::move(r.f), PIKA_FORWARD(Ts, ts)...));
#else
auto&& result = PIKA_INVOKE(PIKA_MOVE(r.f), PIKA_FORWARD(Ts, ts)...);
pika::execution::experimental::set_value(PIKA_MOVE(r.receiver),
PIKA_INVOKE(PIKA_MOVE(r.f), PIKA_FORWARD(Ts, ts)...));
#endif
pika::execution::experimental::set_value(
PIKA_MOVE(r.receiver), PIKA_MOVE(result));
}
},
[&](std::exception_ptr ep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ namespace pika::then_detail {
// Certain versions of GCC with optimizations fail on
// the move with an internal compiler error.
# if defined(PIKA_GCC_VERSION) && (PIKA_GCC_VERSION < 100000)
auto&& result = PIKA_INVOKE(std::move(f), PIKA_FORWARD(Ts, ts)...);
pika::execution::experimental::set_value(PIKA_MOVE(receiver),
PIKA_INVOKE(std::move(f), PIKA_FORWARD(Ts, ts)...));
# else
auto&& result = PIKA_INVOKE(PIKA_MOVE(f), PIKA_FORWARD(Ts, ts)...);
pika::execution::experimental::set_value(PIKA_MOVE(receiver),
PIKA_INVOKE(PIKA_MOVE(f), PIKA_FORWARD(Ts, ts)...));
# endif
pika::execution::experimental::set_value(
PIKA_MOVE(receiver), PIKA_MOVE(result));
}
},
[&](std::exception_ptr ep) {
Expand Down
18 changes: 18 additions & 0 deletions libs/pika/execution/tests/unit/algorithm_then.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ int main()
PIKA_TEST(set_value_called);
}

// This is not recommended, but allowed
{
std::atomic<bool> set_value_called{false};
auto s1 = ex::then(ex::just(), []() -> int& {
static int x = 3;
return x;
});
auto s2 = ex::then(std::move(s1), [](int& x) -> int& {
x *= 4;
return x;
});
auto f = [](int& x) { PIKA_TEST_EQ(x, 12); };
auto r = callback_receiver<decltype(f)>{f, set_value_called};
auto os = ex::connect(std::move(s2), std::move(r));
ex::start(os);
PIKA_TEST(set_value_called);
}

// operator| overload
{
std::atomic<bool> set_value_called{false};
Expand Down