diff --git a/src/error.cpp b/src/error.cpp index a1cba7d02e..cd56785942 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -10,12 +10,12 @@ #include "stdafx.h" #include "error_func.h" -[[noreturn]] void NotReachedError(int line, const char *file) +[[noreturn]] void 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()); } -[[noreturn]] void AssertFailedError(int line, const char *file, const char *expression) +[[noreturn]] void 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 3051047555..e486f04db0 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -349,14 +349,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 -[[noreturn]] void NotReachedError(int line, const char *file); -[[noreturn]] void AssertFailedError(int line, const char *file, const char *expression); -#define NOT_REACHED() NotReachedError(__LINE__, __FILE__) +[[noreturn]] void NOT_REACHED(const std::source_location location = std::source_location::current()); +[[noreturn]] void 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) do { if (!(expression)) [[unlikely]] AssertFailedError(__LINE__, __FILE__, #expression); } while (false) +# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(#expression); } while (false) #endif /* Define JSON_ASSERT, which is used by nlohmann-json. Otherwise the header-file