Luna/luna/include/luna/Check.h

28 lines
1.9 KiB
C
Raw Normal View History

#pragma once
[[noreturn]] extern bool __check_failed(const char* file, const char* line, const char* func, const char* expr);
#ifndef STRINGIZE_VALUE_OF
#define STRINGIZE(x) #x
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
#endif
#define expect(expr, message) \
2022-12-05 12:35:33 +00:00
do { \
if (!(expr)) [[unlikely]] \
{ \
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message); \
} \
} while (0)
#define check(expr) \
do { \
if (!(expr)) [[unlikely]] \
{ \
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr); \
} \
} while (0)
#define unreachable() \
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, "Reached unreachable code")