Skip to content

Commit

Permalink
Add when_all test for const reference exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aurianer committed Jul 13, 2022
1 parent dc874c6 commit 90fcecd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ namespace pika { namespace execution { namespace experimental {

template <template <typename...> class Variant>
using error_types = pika::util::detail::unique_concat_t<
pika::util::detail::transform_t<
typename pika::execution::experimental::sender_traits<
Senders>::template error_types<Variant>...,
Senders>::template error_types<Variant>, std::decay>...,
Variant<std::exception_ptr>>;

static constexpr bool sends_done = false;
Expand Down
45 changes: 45 additions & 0 deletions libs/pika/execution/tests/include/algorithm_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,51 @@ struct error_sender
}
};

template <typename T>
struct const_reference_error_sender
{
template <template <class...> class Tuple,
template <class...> class Variant>
using value_types = Variant<Tuple<T>>;

template <template <class...> class Variant>
using error_types = Variant<std::exception_ptr const&>;

static constexpr bool sends_done = false;

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_value_t(),
pika::execution::experimental::set_error_t(std::exception_ptr&)>;

template <typename R>
struct operation_state
{
std::decay_t<R> r;
friend void tag_invoke(pika::execution::experimental::start_t,
operation_state& os) noexcept
{
try
{
throw std::runtime_error("error");
}
catch (...)
{
auto const& e = std::current_exception();
pika::execution::experimental::set_error(
std::move(os.r), e);
}
}
};

template <typename R>
friend operation_state<R> tag_invoke(
pika::execution::experimental::connect_t, const_reference_error_sender, R&& r)
{
return {std::forward<R>(r)};
}
};

template <typename F>
struct callback_receiver
{
Expand Down
11 changes: 11 additions & 0 deletions libs/pika/execution/tests/unit/algorithm_when_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ int main()
PIKA_TEST(set_error_called);
}

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(
const_reference_error_sender<int>{}, ex::just(42));
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
ex::start(os);
PIKA_TEST(set_error_called);
}

test_adl_isolation(ex::when_all(my_namespace::my_sender{}));

return pika::util::report_errors();
Expand Down

0 comments on commit 90fcecd

Please sign in to comment.