Skip to content

Commit 72dbb93

Browse files
committed
fix a bad test for async_scope::spawn_future
the test was relying on a bug in the implementation of `__tuple`, which this commit also fixes. finally, it fixes a bug in the implementation of `starts_on` that causes `terminate` to be called if moving the sender throws.
1 parent 58b7b38 commit 72dbb93

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

include/stdexec/__detail/__starts_on.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace stdexec {
3737
struct __always {
3838
_Ty __val_;
3939

40-
auto operator()() noexcept -> _Ty {
40+
STDEXEC_ATTRIBUTE((always_inline)) constexpr auto operator()() noexcept(__nothrow_constructible_from<_Ty, _Ty>) -> _Ty {
4141
return static_cast<_Ty&&>(__val_);
4242
}
4343
};

include/stdexec/__detail/__tuple.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ namespace stdexec {
4646

4747
template <class _Ty>
4848
concept __empty = //
49-
STDEXEC_IS_EMPTY(_Ty) && STDEXEC_IS_TRIVIALLY_CONSTRUCTIBLE(_Ty);
49+
STDEXEC_IS_EMPTY(_Ty) && STDEXEC_IS_TRIVIALLY_CONSTRUCTIBLE(_Ty)
50+
&& STDEXEC_IS_TRIVIALLY_COPYABLE(_Ty);
5051

5152
template <__empty _Ty>
5253
inline _Ty __value{};

test/exec/async_scope/test_spawn_future.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,24 @@ namespace {
140140
exec::static_thread_pool pool{2};
141141

142142
struct throwing_copy {
143-
throwing_copy() = default;
143+
bool& should_throw_;
144144

145-
throwing_copy(const throwing_copy&) {
146-
throw std::logic_error("cannot copy");
145+
explicit throwing_copy(bool& should_throw) noexcept
146+
: should_throw_(should_throw) {
147+
}
148+
149+
throwing_copy(const throwing_copy& other)
150+
: should_throw_(other.should_throw_) {
151+
if (should_throw_) {
152+
throw std::logic_error("cannot copy");
153+
}
147154
}
148155
};
149156

150-
ex::sender auto snd =
151-
scope.spawn_future(ex::starts_on(pool.get_scheduler(), ex::just(throwing_copy())));
157+
bool should_throw = false;
158+
ex::sender auto snd = scope.spawn_future(
159+
ex::starts_on(pool.get_scheduler(), ex::just(throwing_copy(should_throw))));
160+
should_throw = true;
152161
try {
153162
sync_wait(std::move(snd));
154163
FAIL("Exceptions should have been thrown");

0 commit comments

Comments
 (0)