From dc795ff4912f78c1aa2c3bf4a4b0ff6c98cd01d5 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 25 Feb 2023 17:41:28 +0100 Subject: [PATCH] luna: Introduce fail(...), a replacement for expect(false, ...) --- luna/include/luna/Check.h | 4 ++++ luna/src/UBSAN.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/luna/include/luna/Check.h b/luna/include/luna/Check.h index ce3b0472..07c5279c 100644 --- a/luna/include/luna/Check.h +++ b/luna/include/luna/Check.h @@ -19,6 +19,10 @@ if (!(expr)) [[unlikely]] { __check_failed(location, message); } \ } while (0) +// Fail with an error message and location. +#define fail(message) __check_failed(SourceLocation::current(), message) +#define fail_at(location, message) __check_failed(location, message) + // Like assert(), but always enabled. #define check(expr) \ do { \ diff --git a/luna/src/UBSAN.cpp b/luna/src/UBSAN.cpp index 15e52676..4f3c25d2 100644 --- a/luna/src/UBSAN.cpp +++ b/luna/src/UBSAN.cpp @@ -7,7 +7,7 @@ using namespace UBSAN::UBInfo; [[noreturn]] void ub_panic(SourceLocation caller = SourceLocation::current()) { - expect_at(false, caller, "Undefined behavior"); + fail_at(caller, "Undefined behavior"); } #define DISPLAY(loc) loc.file, loc.line, loc.column