diff --git a/src/error.cpp b/src/error.cpp index 2d90a83e2b..00d934bb78 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -10,12 +10,12 @@ #include "stdafx.h" #include "error_func.h" -void NORETURN NotReachedError(int line, const char *file) +void NORETURN NOT_REACHED(const std::source_location location) { - FatalError("NOT_REACHED triggered at line {} of {}", line, file); + FatalError("NOT_REACHED triggered at line {} of {}", location.line(), location.file_name()); } -void NORETURN AssertFailedError(int line, const char *file, const char *expression) +void NORETURN AssertFailedError(const char *expression, const std::source_location location) { - FatalError("Assertion failed at line {} of {}: {}", line, file, expression); + FatalError("Assertion failed at line {} of {}: {}", location.line(), location.file_name(), expression); } diff --git a/src/stdafx.h b/src/stdafx.h index 826388c863..a70d93d820 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -385,14 +385,13 @@ static_assert(SIZE_MAX >= UINT32_MAX); /* For the FMT library we only want to use the headers, not link to some library. */ #define FMT_HEADER_ONLY -void NORETURN NotReachedError(int line, const char *file); -void NORETURN AssertFailedError(int line, const char *file, const char *expression); -#define NOT_REACHED() NotReachedError(__LINE__, __FILE__) +void NORETURN NOT_REACHED(const std::source_location location = std::source_location::current()); +void NORETURN AssertFailedError(const char *expression, const std::source_location location = std::source_location::current()); /* For non-debug builds with assertions enabled use the special assertion handler. */ #if defined(NDEBUG) && defined(WITH_ASSERT) # undef assert -# define assert(expression) if (unlikely(!(expression))) AssertFailedError(__LINE__, __FILE__, #expression); +# define assert(expression) if (unlikely(!(expression))) AssertFailedError(#expression); #endif /* Define JSON_ASSERT, which is used by nlohmann-json. Otherwise the header-file