Commit 0dac5b9f authored by Dominik Charousset's avatar Dominik Charousset

Work around weird if constexpr fail

Using `enable_if` should have the same effect as our previous approach
based on `if constexpr`. Alas, `if constexpr` failed to compile on both
GCC and Clang while the equivalent `enable_if` solution works.
parent 9a614951
...@@ -33,6 +33,21 @@ namespace caf::detail { ...@@ -33,6 +33,21 @@ namespace caf::detail {
CAF_CORE_EXPORT void log_cstring_error(const char* cstring); CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
#ifdef CAF_ENABLE_EXCEPTIONS
template <class T>
[[noreturn]] std::enable_if_t<std::is_constructible<T, const char*>::value>
throw_impl(const char* msg) {
throw T{msg};
}
template <class T>
[[noreturn]] void throw_impl(...) {
throw T{};
}
#endif // CAF_ENABLE_EXCEPTIONS
} // namespace caf::detail } // namespace caf::detail
#ifdef CAF_ENABLE_EXCEPTIONS #ifdef CAF_ENABLE_EXCEPTIONS
...@@ -40,10 +55,7 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring); ...@@ -40,10 +55,7 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
# define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \ # define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \
do { \ do { \
::caf::detail::log_cstring_error(msg); \ ::caf::detail::log_cstring_error(msg); \
if constexpr (std::is_constructible<exception_type, const char*>::value) \ ::caf::detail::throw_impl<exception_type>(msg); \
throw exception_type(msg); \
else \
throw exception_type(); \
} while (false) } while (false)
# define CAF_RAISE_ERROR_IMPL_1(msg) \ # define CAF_RAISE_ERROR_IMPL_1(msg) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment