Merge pull request #6445 from lioncash/assert-guard

Assert: Wrap assertion macro bodies in do {} while (0)
This commit is contained in:
Mat M 2018-03-16 12:42:56 -04:00 committed by GitHub
commit 328585ef17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 23 deletions

View File

@ -11,41 +11,59 @@
#ifdef _WIN32 #ifdef _WIN32
#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \ #define ASSERT_MSG(_t_, _a_, _fmt_, ...) \
do \
{ \
if (!(_a_)) \ if (!(_a_)) \
{ \ { \
if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__)) \ if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__)) \
Crash(); \ Crash(); \
} } \
} while (0)
#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ #define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \
do \
{ \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \ if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
{ \ { \
ERROR_LOG(_t_, _msg_, __VA_ARGS__); \ ERROR_LOG(_t_, _msg_, __VA_ARGS__); \
if (!PanicYesNo(_msg_, __VA_ARGS__)) \ if (!PanicYesNo(_msg_, __VA_ARGS__)) \
Crash(); \ Crash(); \
} } \
} while (0)
#else #else
#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \ #define ASSERT_MSG(_t_, _a_, _fmt_, ...) \
do \
{ \
if (!(_a_)) \ if (!(_a_)) \
{ \ { \
if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \ if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \
Crash(); \ Crash(); \
} } \
} while (0)
#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ #define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \
do \
{ \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \ if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
{ \ { \
ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \ ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \
if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \ if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \
Crash(); \ Crash(); \
} } \
} while (0)
#endif #endif
#define ASSERT(_a_) \ #define ASSERT(_a_) \
do \
{ \
ASSERT_MSG(MASTER_LOG, _a_, \ ASSERT_MSG(MASTER_LOG, _a_, \
_trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \ _trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \
__LINE__, __FILE__) __LINE__, __FILE__); \
} while (0)
#define DEBUG_ASSERT(_t_, _a_) \ #define DEBUG_ASSERT(_t_, _a_) \
do \
{ \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \ if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \
ASSERT(_a_) ASSERT(_a_); \
} while (0)