mirror of
https://github.com/azahar-emu/mcl
synced 2025-11-06 15:10:05 +01:00
assert: Handle expr strings separately
This commit is contained in:
parent
b38a9d2ef8
commit
678aa32a8b
@ -13,12 +13,12 @@
|
||||
|
||||
namespace mcl::detail {
|
||||
|
||||
[[noreturn]] void assert_terminate_impl(fmt::string_view msg, fmt::format_args args);
|
||||
[[noreturn]] void assert_terminate_impl(const char* expr_str, fmt::string_view msg, fmt::format_args args);
|
||||
|
||||
template<typename... Ts>
|
||||
[[noreturn]] void assert_terminate(fmt::string_view msg, Ts... args)
|
||||
[[noreturn]] void assert_terminate(const char* expr_str, fmt::string_view msg, Ts... args)
|
||||
{
|
||||
assert_terminate_impl(msg, fmt::make_format_args(args...));
|
||||
assert_terminate_impl(expr_str, msg, fmt::make_format_args(args...));
|
||||
}
|
||||
|
||||
} // namespace mcl::detail
|
||||
@ -33,25 +33,25 @@ template<typename... Ts>
|
||||
} \
|
||||
} else { \
|
||||
if (!(expr)) [[unlikely]] { \
|
||||
::mcl::detail::assert_terminate(#expr); \
|
||||
::mcl::detail::assert_terminate(#expr, "(none)"); \
|
||||
} \
|
||||
} \
|
||||
}()
|
||||
|
||||
#define ASSERT_MSG(expr, ...) \
|
||||
[&] { \
|
||||
if (std::is_constant_evaluated()) { \
|
||||
if (!(expr)) { \
|
||||
throw std::logic_error{"ASSERT_MSG failed at compile time"}; \
|
||||
} \
|
||||
} else { \
|
||||
if (!(expr)) [[unlikely]] { \
|
||||
::mcl::detail::assert_terminate(#expr "\nMessage: " __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
#define ASSERT_MSG(expr, ...) \
|
||||
[&] { \
|
||||
if (std::is_constant_evaluated()) { \
|
||||
if (!(expr)) { \
|
||||
throw std::logic_error{"ASSERT_MSG failed at compile time"}; \
|
||||
} \
|
||||
} else { \
|
||||
if (!(expr)) [[unlikely]] { \
|
||||
::mcl::detail::assert_terminate(#expr, __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
}()
|
||||
|
||||
#define ASSERT_FALSE(...) ::mcl::detail::assert_terminate("false\nMessage: " __VA_ARGS__)
|
||||
#define ASSERT_FALSE(...) ::mcl::detail::assert_terminate("false", __VA_ARGS__)
|
||||
|
||||
#if defined(NDEBUG) || defined(MCL_IGNORE_ASSERTS)
|
||||
# define DEBUG_ASSERT(expr) ASSUME(expr)
|
||||
|
||||
@ -11,9 +11,9 @@
|
||||
|
||||
namespace mcl::detail {
|
||||
|
||||
[[noreturn]] void assert_terminate_impl(fmt::string_view msg, fmt::format_args args)
|
||||
[[noreturn]] void assert_terminate_impl(const char* expr_str, fmt::string_view msg, fmt::format_args args)
|
||||
{
|
||||
fmt::print(stderr, "assertion failed: ");
|
||||
fmt::print(stderr, "assertion failed: {}\nMessage:", expr_str);
|
||||
fmt::vprint(stderr, msg, args);
|
||||
std::fflush(stderr);
|
||||
std::terminate();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user