mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
Codechange: use std::source_location over __FILE__ and __LINE__ for NOT_REACHED
This commit is contained in:
parent
bab5a8a787
commit
e4b3f3f495
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user