From 4d2fc2883472c0c39012adccf161f7fbe36d2707 Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 30 Jan 2024 22:42:20 +0100 Subject: [PATCH] Codechange: wrap 'if' in macros into 'do { ... } while (false)', so it does not break on following 'else'. --- src/debug.h | 2 +- src/stdafx.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug.h b/src/debug.h index f3a9bf8a01..fbd39683c6 100644 --- a/src/debug.h +++ b/src/debug.h @@ -34,7 +34,7 @@ * @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown. * @param format_string The formatting string of the message. */ -#define Debug(category, level, format_string, ...) if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) +#define Debug(category, level, format_string, ...) do { if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)); } while (false) void DebugPrint(const char *category, int level, const std::string &message); extern int _debug_driver_level; diff --git a/src/stdafx.h b/src/stdafx.h index aec18c2b2e..8b474920e7 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -392,7 +392,7 @@ void NORETURN AssertFailedError(int line, const char *file, const char *expressi /* 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) do { if (unlikely(!(expression))) AssertFailedError(__LINE__, __FILE__, #expression); } while (false) #endif /* Define JSON_ASSERT, which is used by nlohmann-json. Otherwise the header-file