Skip to content
Permalink
Browse files
Merge pull request #6445 from lioncash/assert-guard
Assert: Wrap assertion macro bodies in do {} while (0)
  • Loading branch information
lioncash committed Mar 16, 2018
2 parents 9f4d512 + f44e2dc commit 328585e
Showing 1 changed file with 41 additions and 23 deletions.
@@ -11,41 +11,59 @@

#ifdef _WIN32
#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \
if (!(_a_)) \
do \
{ \
if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__)) \
Crash(); \
}
if (!(_a_)) \
{ \
if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__)) \
Crash(); \
} \
} while (0)

#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
do \
{ \
ERROR_LOG(_t_, _msg_, __VA_ARGS__); \
if (!PanicYesNo(_msg_, __VA_ARGS__)) \
Crash(); \
}
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
{ \
ERROR_LOG(_t_, _msg_, __VA_ARGS__); \
if (!PanicYesNo(_msg_, __VA_ARGS__)) \
Crash(); \
} \
} while (0)
#else
#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \
if (!(_a_)) \
do \
{ \
if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \
Crash(); \
}
if (!(_a_)) \
{ \
if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \
Crash(); \
} \
} while (0)

#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
do \
{ \
ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \
if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \
Crash(); \
}
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \
{ \
ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \
if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \
Crash(); \
} \
} while (0)
#endif

#define ASSERT(_a_) \
ASSERT_MSG(MASTER_LOG, _a_, \
_trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \
__LINE__, __FILE__)
do \
{ \
ASSERT_MSG(MASTER_LOG, _a_, \
_trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \
__LINE__, __FILE__); \
} while (0)

#define DEBUG_ASSERT(_t_, _a_) \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \
ASSERT(_a_)
do \
{ \
if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \
ASSERT(_a_); \
} while (0)

0 comments on commit 328585e

Please sign in to comment.