Skip to content

Commit a609c73

Browse files
Fix iterate subscribe exception specification (#2206)
* Fix iterate subscribe exception specification * Format iterate subscribe exception specification * Guard iterate exception test
1 parent e92245d commit a609c73

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

include/exec/sequence/iterate.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ namespace experimental::execution
178178
struct __subscribe_fn
179179
{
180180
template <class _Range>
181-
constexpr auto operator()(__ignore, _Range&& __range) noexcept
181+
constexpr auto operator()(__ignore, _Range&& __range)
182+
noexcept(noexcept(std::ranges::begin(static_cast<_Range&&>(__range)))
183+
&& noexcept(std::ranges::end(static_cast<_Range&&>(__range)))
184+
&& __nothrow_move_constructible<std::ranges::iterator_t<_Range>,
185+
std::ranges::sentinel_t<_Range>,
186+
_Receiver>)
182187
{
183188
return __operation{std::ranges::begin(static_cast<_Range&&>(__range)),
184189
std::ranges::end(static_cast<_Range&&>(__range)),

test/exec/sequence/test_iterate.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525
namespace
2626
{
2727

28+
#if !STDEXEC_NO_STDCPP_EXCEPTIONS()
29+
struct begin_error
30+
{};
31+
32+
struct begin_throws_range
33+
{
34+
using iterator = std::array<int, 1>::iterator;
35+
36+
iterator begin()
37+
{
38+
throw begin_error{};
39+
}
40+
41+
iterator end() noexcept
42+
{
43+
return values.end();
44+
}
45+
46+
std::array<int, 1> values{0};
47+
};
48+
#endif // !STDEXEC_NO_STDCPP_EXCEPTIONS()
49+
2850
template <class Receiver>
2951
struct sum_item_rcvr
3052
{
@@ -140,4 +162,15 @@ namespace
140162
CHECK(sum == (42 + 43 + 44 + 1));
141163
}
142164

165+
#if !STDEXEC_NO_STDCPP_EXCEPTIONS()
166+
TEST_CASE("iterate - subscribe propagates begin exceptions", "[sequence_senders][iterate]")
167+
{
168+
auto iterate = exec::iterate(begin_throws_range{});
169+
int sum = 0;
170+
171+
STATIC_REQUIRE_FALSE(noexcept(exec::subscribe(iterate, sum_receiver<>{.sum_ = sum})));
172+
CHECK_THROWS_AS(exec::subscribe(iterate, sum_receiver<>{.sum_ = sum}), begin_error);
173+
}
174+
#endif // !STDEXEC_NO_STDCPP_EXCEPTIONS()
175+
143176
} // namespace

0 commit comments

Comments
 (0)