Skip to content
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
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ EmptyLineBeforeAccessModifier: Leave
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IfMacros: [
STDEXEC_CATCH'
'STDEXEC_CATCH'
]
IncludeBlocks: Preserve
IndentAccessModifiers: false
Expand All @@ -88,6 +88,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LineEnding: LF
Macros: [
'STDEXEC_CATCH_FALLTHROUGH= ',
'STDEXEC_MEMFN_DECL(...)=__VA_ARGS__',
'STDEXEC_ATTRIBUTE(...)=__attribute__((__VA_ARGS__))',
'STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS=[[no_unique_address]]',
Expand Down
1 change: 1 addition & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CompileFlags:
- "-ftemplate-backtrace-limit=0"
- "-std=gnu++20"
- "-DSTDEXEC_CLANGD_INVOKED"
- "-stdlib=libc++"
Remove:
- "-stdpar*"
# strip CUDA fatbin args
Expand Down
7 changes: 5 additions & 2 deletions examples/hello_coro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ auto main() -> int {
auto [i] = stdexec::sync_wait(async_answer2(just(42), just())).value();
std::cout << "The answer is " << i.value() << '\n';
}
STDEXEC_CATCH(const std::exception& e) {
std::cout << e.what() << '\n';
STDEXEC_CATCH(std::exception& e) {
std::cerr << "error: " << e.what() << '\n';
}
STDEXEC_CATCH_ALL {
std::cerr << "unknown error\n";
}
}
#else
Expand Down
6 changes: 3 additions & 3 deletions include/exec/__detail/__system_context_default_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace exec::__system_context_default_impl {
__schedule_operation_t::__construct_maybe_alloc(__storage, &__r, std::move(__sndr));
__os->start();
}
STDEXEC_CATCH(std::exception & __e) {
STDEXEC_CATCH_ALL {
__r.set_error(std::current_exception());
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ namespace exec::__system_context_default_impl {
__storage, &__r, std::move(__sndr));
__os->start();
}
STDEXEC_CATCH(std::exception & __e) {
STDEXEC_CATCH_ALL {
__r.set_error(std::current_exception());
}
}
Expand All @@ -297,7 +297,7 @@ namespace exec::__system_context_default_impl {
__storage, &__r, std::move(__sndr));
__os->start();
}
STDEXEC_CATCH(std::exception & __e) {
STDEXEC_CATCH_ALL {
__r.set_error(std::current_exception());
}
}
Expand Down
30 changes: 16 additions & 14 deletions include/stdexec/__detail/__config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ namespace stdexec {
# include <cuda_runtime_api.h>
#endif

// clang-format off

// The following macros are used to conditionally compile exception handling code. They
// are used in the same way as `try` and `catch`, but they allow for different behavior
// based on whether exceptions are enabled or not, and whether the code is being compiled
Expand All @@ -559,28 +561,28 @@ namespace stdexec {
// printf("unknown error\n");
// }
#if STDEXEC_STD_NO_EXCEPTIONS()
# define STDEXEC_TRY if constexpr (true)
# define STDEXEC_CATCH(...) \
else if constexpr ([[maybe_unused]] __VA_ARGS__ = ::stdexec::_catch_any_lvalue{}; false)
# define STDEXEC_CATCH_ALL \
else if constexpr (true) { \
} \
else
# define STDEXEC_THROW(...) ::stdexec::__terminate()
# define STDEXEC_TRY if constexpr (true) {
# define STDEXEC_CATCH(...) } else if constexpr (__VA_ARGS__ = ::stdexec::__catch_any_lvalue; false) {
# define STDEXEC_CATCH_ALL } else if constexpr (true) {} else
# define STDEXEC_THROW(...) ::stdexec::__terminate()
# define STDEXEC_CATCH_FALLTHROUGH } else {}
#else
# define STDEXEC_TRY try
# define STDEXEC_CATCH catch
# define STDEXEC_CATCH_ALL STDEXEC_CATCH(...)
# define STDEXEC_THROW(...) throw __VA_ARGS__
# define STDEXEC_TRY try
# define STDEXEC_CATCH catch
# define STDEXEC_CATCH_ALL catch(...)
# define STDEXEC_THROW(...) throw __VA_ARGS__
# define STDEXEC_CATCH_FALLTHROUGH
#endif

// clang-format on

namespace stdexec {
// Used by the STDEXEC_CATCH macro to provide a stub initialization of the exception object.
struct _catch_any_lvalue {
constexpr struct __catch_any_lvalue_t {
template <class _Tp>
STDEXEC_ATTRIBUTE(host, device)
operator _Tp&() const noexcept;
};
} __catch_any_lvalue{};

STDEXEC_ATTRIBUTE(noreturn, host, device)
inline void __terminate() noexcept {
Expand Down
3 changes: 3 additions & 0 deletions test/exec/async_scope/test_spawn_future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ namespace {
STDEXEC_CATCH(const std::logic_error& e) {
SUCCEED("correct exception caught");
}
STDEXEC_CATCH_ALL {
FAIL("invalid exception caught");
}
sync_wait(scope.on_empty());
}
#endif // !STDEXEC_STD_NO_EXCEPTIONS()
Expand Down
3 changes: 3 additions & 0 deletions test/exec/test_libdispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@ namespace {
STDEXEC_CATCH(int e) {
CHECK(e == 999);
}
STDEXEC_CATCH_ALL {
FAIL("invalid exception caught");
}
}
} // namespace
3 changes: 3 additions & 0 deletions test/rrd/async_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ struct async_scope_future_set_result : rl::test_suite<async_scope_future_set_res
STDEXEC_CATCH(const std::logic_error&) {
threw = true;
}
STDEXEC_CATCH_ALL {
RL_ASSERT(false);
}
RL_ASSERT(threw);
ex::sync_wait(scope.on_empty());
}
Expand Down
1 change: 1 addition & 0 deletions test/stdexec/algos/adaptors/test_let_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace {
STDEXEC_CATCH(const std::exception& e) {
return ex::just(std::string{e.what()});
}
STDEXEC_CATCH_FALLTHROUGH
});
wait_for_value(std::move(snd), std::string{"error description"});
(void) snd;
Expand Down
3 changes: 3 additions & 0 deletions test/test_common/receivers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ namespace {
STDEXEC_CATCH(const std::exception& e) {
FAIL("Exception thrown: " << e.what());
}
STDEXEC_CATCH_ALL {
FAIL("Exception thrown");
}
}
};

Expand Down
Loading