Skip to content

Commit 0c0b519

Browse files
authored
get everything running with -fno-exceptions (#1556)
1 parent af79a8c commit 0c0b519

36 files changed

Lines changed: 207 additions & 284 deletions

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ SpacesInConditionalStatement: false
152152
SpacesInContainerLiterals: true
153153
SpacesInParentheses: false
154154
Standard: c++20
155+
StatementMacros: [
156+
'STDEXEC_IF_HOST',
157+
'STDEXEC_IF_DEVICE',
158+
]
155159
TabWidth: 0
156160
TypenameMacros: []
157161
UseTab: Never

examples/algorithms/retry.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ struct _op {
9191
}
9292

9393
void _retry() noexcept {
94-
try {
94+
STDEXEC_TRY {
9595
o_.emplace(_connect()); // potentially throwing
9696
stdexec::start(*o_);
97-
} catch (...) {
97+
}
98+
STDEXEC_CATCH_ALL {
9899
stdexec::set_error(static_cast<R&&>(r_), std::current_exception());
99100
}
100101
}

examples/algorithms/then.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class _then_receiver : public stdexec::receiver_adaptor<_then_receiver<R, F>, R>
4141
template <class... As>
4242
requires stdexec::receiver_of<R, _completions<As...>>
4343
void set_value(As&&... as) && noexcept {
44-
try {
44+
STDEXEC_TRY {
4545
stdexec::set_value(
4646
std::move(*this).base(), std::invoke(static_cast<F&&>(f_), static_cast<As&&>(as)...));
47-
} catch (...) {
47+
}
48+
STDEXEC_CATCH_ALL {
4849
stdexec::set_error(std::move(*this).base(), std::current_exception());
4950
}
5051
}

examples/benchmark/static_thread_pool_old.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,15 @@ namespace exec_old {
274274

275275
threads_.reserve(threadCount);
276276

277-
try {
277+
STDEXEC_TRY {
278278
for (std::uint32_t i = 0; i < threadCount; ++i) {
279279
threads_.emplace_back([this, i] { run(i); });
280280
}
281-
} catch (...) {
281+
}
282+
STDEXEC_CATCH_ALL {
282283
request_stop();
283284
join();
284-
throw;
285+
STDEXEC_THROW();
285286
}
286287
}
287288

examples/hello_coro.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ auto async_stop_token() -> exec::task<std::optional<stdexec::inplace_stop_token>
4141
}
4242

4343
auto main() -> int {
44-
try {
44+
STDEXEC_TRY {
4545
// Awaitables are implicitly senders:
4646
auto [i] = stdexec::sync_wait(async_answer2(just(42), just())).value();
4747
std::cout << "The answer is " << i.value() << '\n';
48-
} catch (std::exception& e) {
48+
}
49+
STDEXEC_CATCH(const std::exception& e) {
4950
std::cout << e.what() << '\n';
5051
}
5152
}

examples/server_theme/let_value.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
// Use a thread pool
5353
#include "exec/static_thread_pool.hpp"
5454

55+
#if !STDEXEC_STD_NO_EXCEPTIONS()
5556
namespace ex = stdexec;
5657

5758
struct http_request {
@@ -151,3 +152,11 @@ auto main() -> int {
151152

152153
return 0;
153154
}
155+
156+
#else
157+
158+
int main() {
159+
std::cout << "This example requires C++ exceptions to be enabled.\n";
160+
return 0;
161+
}
162+
#endif // !STDEXEC_STD_NO_EXCEPTIONS()

include/exec/any_sender_of.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ namespace exec {
347347
}
348348
STDEXEC_CATCH_ALL {
349349
std::allocator_traits<_Alloc>::deallocate(__alloc, __pointer, 1);
350-
throw;
350+
STDEXEC_THROW();
351351
}
352352
__object_pointer_ = __pointer;
353353
}
@@ -512,7 +512,7 @@ namespace exec {
512512
}
513513
STDEXEC_CATCH_ALL {
514514
std::allocator_traits<_Alloc>::deallocate(__alloc, __pointer, 1);
515-
throw;
515+
STDEXEC_THROW();
516516
}
517517
__object_pointer_ = __pointer;
518518
}

include/exec/linux/io_uring_context.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace exec {
6262

6363
inline void __throw_error_code_if(bool __cond, int __ec) {
6464
if (__cond) {
65-
throw std::system_error(__ec, std::system_category());
65+
STDEXEC_THROW(std::system_error(__ec, std::system_category()));
6666
}
6767
}
6868

@@ -371,14 +371,15 @@ namespace exec {
371371

372372
void wakeup() {
373373
if (auto __ec = try_wakeup()) {
374-
throw std::system_error{__ec};
374+
STDEXEC_THROW(std::system_error{__ec});
375375
}
376376
}
377377

378378
/// @brief Resets the io context to its initial state.
379379
void reset() {
380380
if (__is_running_.load(std::memory_order_relaxed) || __n_total_submitted_ > 0) {
381-
throw std::runtime_error("exec::io_uring_context::reset() called on a running context");
381+
STDEXEC_THROW(
382+
std::runtime_error("exec::io_uring_context::reset() called on a running context"));
382383
}
383384
__n_submissions_in_flight_.store(0, std::memory_order_relaxed);
384385
__stop_source_.reset();
@@ -474,7 +475,8 @@ namespace exec {
474475
// Only one thread of execution is allowed to drive the io context.
475476
if (!__is_running_
476477
.compare_exchange_strong(expected_running, true, std::memory_order_relaxed)) {
477-
throw std::runtime_error("exec::io_uring_context::run() called on a running context");
478+
STDEXEC_THROW(
479+
std::runtime_error("exec::io_uring_context::run() called on a running context"));
478480
} else {
479481
// Check whether we restart the context after a context-wide stop.
480482
// We have to reset the stop source in this case.

include/exec/static_thread_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ namespace exec {
736736
STDEXEC_CATCH_ALL {
737737
request_stop();
738738
join();
739-
throw;
739+
STDEXEC_THROW();
740740
}
741741
}
742742

include/exec/system_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ namespace exec {
637637
inline auto get_parallel_scheduler() -> parallel_scheduler {
638638
auto __impl = system_context_replaceability::query_parallel_scheduler_backend();
639639
if (!__impl) {
640-
throw std::runtime_error{"No system context implementation found"};
640+
STDEXEC_THROW(std::runtime_error{"No system context implementation found"});
641641
}
642642
return parallel_scheduler{std::move(__impl)};
643643
}

0 commit comments

Comments
 (0)