Skip to content

Commit

Permalink
Some cleanup of the assertion macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Feb 20, 2024
1 parent f83ba61 commit e2b8958
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions include/assert/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ namespace libassert::detail {
fail(params->type, printer);
}

// TODO: Re-evaluate benefit of this at all in non-cold path code
template<typename A, typename B, typename C, typename... Args>
LIBASSERT_ATTR_COLD LIBASSERT_ATTR_NOINLINE [[nodiscard]]
expression_decomposer<A, B, C> process_assert_fail_m(
Expand All @@ -1320,6 +1321,16 @@ namespace libassert::detail {
return decomposer;
}

template<typename A, typename B, typename C, typename... Args>
LIBASSERT_ATTR_COLD LIBASSERT_ATTR_NOINLINE
void process_assert_fail_n(
expression_decomposer<A, B, C> decomposer,
const assert_static_parameters* params,
Args&&... args
) {
process_assert_fail(decomposer, params, std::forward<Args>(args)...);
}

template<typename T>
struct assert_value_wrapper {
T value;
Expand Down Expand Up @@ -1553,12 +1564,7 @@ inline void ERROR_ASSERTION_FAILURE_IN_CONSTEXPR_CONTEXT() {
libassert::detail::expression_decomposer{} << expr \
); \
LIBASSERT_WARNING_PRAGMA_POP_GCC \
decltype(auto) libassert_value = libassert_decomposer.get_value(); \
constexpr bool libassert_ret_lhs = libassert_decomposer.ret_lhs(); \
/* For *some* godforsaken reason static_cast<bool> causes an ICE in MSVC here. Something very specific */ \
/* about casting a decltype(auto) value inside a lambda. Workaround is to put it in a wrapper. */ \
/* https://godbolt.org/z/Kq8Wb6q5j https://godbolt.org/z/nMnqnsMYx */ \
if(LIBASSERT_STRONG_EXPECT(!LIBASSERT_STATIC_CAST_TO_BOOL(libassert_value), 0)) { \
if(LIBASSERT_STRONG_EXPECT(!static_cast<bool>(libassert_decomposer.get_value()), 0)) { \
ERROR_ASSERTION_FAILURE_IN_CONSTEXPR_CONTEXT(); \
failaction \
LIBASSERT_STATIC_DATA(name, libassert::assert_type::type, #expr, __VA_ARGS__) \
Expand All @@ -1570,14 +1576,11 @@ inline void ERROR_ASSERTION_FAILURE_IN_CONSTEXPR_CONTEXT() {
); \
} else { \
/* std::move it to assert_fail_m, will be moved back to r */ \
auto libassert_r = process_assert_fail_m( \
process_assert_fail_n( \
std::move(libassert_decomposer), \
libassert_params \
LIBASSERT_VA_ARGS(__VA_ARGS__) LIBASSERT_PRETTY_FUNCTION_ARG \
); \
/* can't move-assign back to decomposer if it holds reference members */ \
LIBASSERT_DESTROY_DECOMPOSER; \
new (&libassert_decomposer) libassert::detail::expression_decomposer(std::move(libassert_r)); \
} \
} \
LIBASSERT_WARNING_PRAGMA_POP_CLANG \
Expand Down

0 comments on commit e2b8958

Please sign in to comment.