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