40 lines
2.0 KiB
C++
40 lines
2.0 KiB
C++
//! Support Library Assert Wrappers
|
|
//!
|
|
//! The Support Library uses its own assertion system which is more flexible than the
|
|
//! standard C library's assertion macros.
|
|
//!
|
|
//! They are not intended to be directly compatible with some of the quirks
|
|
//! the Standard C library allows (like using assert() as an expression).
|
|
//!
|
|
//! They are:
|
|
//! - BASE_ASSERT()
|
|
//! - active in debug builds and removed on release
|
|
//! - BASE_CHECK()
|
|
//! - always active, even in release builds
|
|
|
|
#pragma once
|
|
|
|
#include <format>
|
|
|
|
namespace base {
|
|
[[noreturn]] void ExitMsg(const char* message);
|
|
} // namespace base
|
|
|
|
#ifdef BASE_DEBUG
|
|
#define BASE_ASSERT(expr, fmt, ...) \
|
|
if(!(expr)) [[unlikely]] { \
|
|
auto msg = std::format("Assertion \"{}\" @ {}:{} failed with message: {}", #expr, __FILE__, __LINE__, std::format(fmt, ##__VA_ARGS__)); \
|
|
::base::ExitMsg(msg.c_str()); \
|
|
__builtin_unreachable(); \
|
|
}
|
|
#else
|
|
#define BASE_ASSERT(expr, format, ...)
|
|
#endif
|
|
|
|
#define BASE_CHECK(expr, fmt, ...) \
|
|
if(!(expr)) [[unlikely]] { \
|
|
auto msg = std::format("Check \"{}\" @ {}:{} failed with message: {}", #expr, __FILE__, __LINE__, std::format(fmt, ##__VA_ARGS__)); \
|
|
::base::ExitMsg(msg.c_str()); \
|
|
__builtin_unreachable(); \
|
|
}
|