Luna/luna/include/luna/Check.h
apio 34a9b35037
All checks were successful
continuous-integration/drone/push Build is passing
Option, Result: Propagate caller locations when erroring out
2023-01-22 12:00:52 +01:00

36 lines
2.0 KiB
C

#pragma once
#include <luna/SourceLocation.h>
[[noreturn]] extern bool __check_failed(SourceLocation location, const char* expr);
#ifndef STRINGIZE_VALUE_OF
#define STRINGIZE(x) #x
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
#endif
// Like check(), but with a custom error message.
#define expect(expr, message) \
do { \
if (!(expr)) [[unlikely]] { __check_failed(SourceLocation::current(), message); } \
} while (0)
#define expect_at(expr, location, message) \
do { \
if (!(expr)) [[unlikely]] { __check_failed(location, message); } \
} while (0)
// Like assert(), but always enabled.
#define check(expr) \
do { \
if (!(expr)) [[unlikely]] { __check_failed(SourceLocation::current(), #expr); } \
} while (0)
#define check_at(expr, location) \
do { \
if (!(expr)) [[unlikely]] { __check_failed(location, #expr); } \
} while (0)
#define unreachable() __check_failed(SourceLocation::current(), "Reached unreachable code")
#define todo() __check_failed(SourceLocation::current(), "Reached a TODO!")