Skip to content

Commit 9fc6fa7

Browse files
committed
Reduce complexity of LIBASSERT_INVOKE_VAL, doreturn was unused
1 parent 58a0142 commit 9fc6fa7

2 files changed

Lines changed: 20 additions & 28 deletions

File tree

include/libassert/assert-macros.hpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@
7979
#define LIBASSERT_STRINGIFY(x) #x,
8080
#define LIBASSERT_COMMA ,
8181

82-
// Church boolean
83-
#define LIBASSERT_IF(b) LIBASSERT_IF_##b
84-
#define LIBASSERT_IF_true(t,...) t
85-
#define LIBASSERT_IF_false(t,f,...) f
86-
8782
#if LIBASSERT_IS_CLANG || LIBASSERT_IS_GCC
8883
#if LIBASSERT_IS_GCC
8984
#define LIBASSERT_EXPRESSION_DECOMP_WARNING_PRAGMA_GCC \
@@ -280,7 +275,7 @@ LIBASSERT_END_NAMESPACE
280275
}
281276
LIBASSERT_END_NAMESPACE
282277
#endif
283-
#define LIBASSERT_INVOKE_VAL(expr, doreturn, check_expression, name, type, failaction, ...) \
278+
#define LIBASSERT_INVOKE_VAL(expr, check_expression, name, type, failaction, ...) \
284279
/* must push/pop out here due to nasty clang bug https://github.com/llvm/llvm-project/issues/63897 */ \
285280
/* must do awful stuff to workaround differences in where gcc and clang allow these directives to go */ \
286281
LIBASSERT_WARNING_PRAGMA_PUSH_CLANG \
@@ -327,11 +322,10 @@ LIBASSERT_END_NAMESPACE
327322
/* https://timsong-cpp.github.io/cppwp/n4659/basic.life#8.3 */ \
328323
/* Note: Somewhat relying on this call being inlined so inefficiency is eliminated */ \
329324
libassert::detail::get_expression_return_value< \
330-
doreturn LIBASSERT_COMMA \
331325
libassert_ret_lhs LIBASSERT_COMMA \
332326
std::is_lvalue_reference_v<decltype(libassert_value)> \
333327
>(libassert_value, *std::launder(&libassert_decomposer)); \
334-
) LIBASSERT_IF(doreturn)(.value,) \
328+
).value \
335329
LIBASSERT_WARNING_PRAGMA_POP_CLANG
336330

337331
#ifdef NDEBUG
@@ -369,14 +363,14 @@ LIBASSERT_END_NAMESPACE
369363
// value variants
370364

371365
#ifndef NDEBUG
372-
#define LIBASSERT_DEBUG_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, true, "DEBUG_ASSERT_VAL", debug_assertion, , __VA_ARGS__)
366+
#define LIBASSERT_DEBUG_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, "DEBUG_ASSERT_VAL", debug_assertion, , __VA_ARGS__)
373367
#else
374-
#define LIBASSERT_DEBUG_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, false, "DEBUG_ASSERT_VAL", debug_assertion, , __VA_ARGS__)
368+
#define LIBASSERT_DEBUG_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, false, "DEBUG_ASSERT_VAL", debug_assertion, , __VA_ARGS__)
375369
#endif
376370

377-
#define LIBASSERT_ASSUME_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, true, "ASSUME_VAL", assumption, LIBASSERT_ASSUME_ACTION, __VA_ARGS__)
371+
#define LIBASSERT_ASSUME_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, "ASSUME_VAL", assumption, LIBASSERT_ASSUME_ACTION, __VA_ARGS__)
378372

379-
#define LIBASSERT_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, true, "ASSERT_VAL", assertion, , __VA_ARGS__)
373+
#define LIBASSERT_ASSERT_VAL(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, "ASSERT_VAL", assertion, , __VA_ARGS__)
380374

381375
// non-prefixed versions
382376

@@ -415,14 +409,14 @@ LIBASSERT_END_NAMESPACE
415409

416410
#ifdef LIBASSERT_LOWERCASE
417411
#ifndef NDEBUG
418-
#define debug_assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, true, "debug_assert_val", debug_assertion, , __VA_ARGS__)
412+
#define debug_assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, "debug_assert_val", debug_assertion, , __VA_ARGS__)
419413
#else
420-
#define debug_assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, false, "debug_assert_val", debug_assertion, , __VA_ARGS__)
414+
#define debug_assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, false, "debug_assert_val", debug_assertion, , __VA_ARGS__)
421415
#endif
422416
#endif
423417

424418
#ifdef LIBASSERT_LOWERCASE
425-
#define assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, true, "assert_val", assertion, , __VA_ARGS__)
419+
#define assert_val(expr, ...) LIBASSERT_INVOKE_VAL(expr, true, "assert_val", assertion, , __VA_ARGS__)
426420
#endif
427421

428422
// Wrapper macro to allow support for C++26's user generated static_assert messages.

include/libassert/assert.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -489,23 +489,21 @@ LIBASSERT_END_NAMESPACE
489489
};
490490

491491
template<
492-
bool R, bool ret_lhs, bool value_is_lval_ref,
492+
bool ret_lhs, bool value_is_lval_ref,
493493
typename T, typename A, typename B, typename C
494494
>
495495
constexpr auto get_expression_return_value(T& value, expression_decomposer<A, B, C>& decomposer) {
496-
if constexpr(R) {
497-
if constexpr(ret_lhs) {
498-
if constexpr(std::is_lvalue_reference_v<A>) {
499-
return assert_value_wrapper<A>{decomposer.take_lhs()};
500-
} else {
501-
return assert_value_wrapper<A>{std::move(decomposer.take_lhs())};
502-
}
496+
if constexpr(ret_lhs) {
497+
if constexpr(std::is_lvalue_reference_v<A>) {
498+
return assert_value_wrapper<A>{decomposer.take_lhs()};
503499
} else {
504-
if constexpr(value_is_lval_ref) {
505-
return assert_value_wrapper<T&>{value};
506-
} else {
507-
return assert_value_wrapper<T>{std::move(value)};
508-
}
500+
return assert_value_wrapper<A>{std::move(decomposer.take_lhs())};
501+
}
502+
} else {
503+
if constexpr(value_is_lval_ref) {
504+
return assert_value_wrapper<T&>{value};
505+
} else {
506+
return assert_value_wrapper<T>{std::move(value)};
509507
}
510508
}
511509
}

0 commit comments

Comments
 (0)