mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Modified the DBG and jassert macros to force users to follow them with a semi-colon. This can avoid some nasty and subtle mistakes when the macros are elided in a release build.
This commit is contained in:
parent
e60aa581d6
commit
80e7a36691
1 changed files with 21 additions and 7 deletions
|
|
@ -94,20 +94,34 @@
|
|||
#define JUCE_ANALYZER_NORETURN
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_MSVC && ! DOXYGEN
|
||||
#define MACRO_WITH_FORCED_SEMICOLON(x) \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable:4127)) \
|
||||
do { x } while (false) \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
/** This is the good old C++ trick for creating a macro that forces the user to put
|
||||
a semicolon after it when they use it.
|
||||
*/
|
||||
#define MACRO_WITH_FORCED_SEMICOLON(x) do { x } while (false)
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_DEBUG || DOXYGEN
|
||||
/** Writes a string to the standard error stream.
|
||||
This is only compiled in a debug build.
|
||||
@see Logger::outputDebugString
|
||||
*/
|
||||
#define DBG(dbgtext) { juce::String tempDbgBuf; tempDbgBuf << dbgtext; juce::Logger::outputDebugString (tempDbgBuf); }
|
||||
#define DBG(dbgtext) MACRO_WITH_FORCED_SEMICOLON (juce::String tempDbgBuf; tempDbgBuf << dbgtext; juce::Logger::outputDebugString (tempDbgBuf);)
|
||||
|
||||
//==============================================================================
|
||||
/** This will always cause an assertion failure.
|
||||
It is only compiled in a debug build, (unless JUCE_LOG_ASSERTIONS is enabled for your build).
|
||||
@see jassert
|
||||
*/
|
||||
#define jassertfalse { juce_LogCurrentAssertion; if (juce::juce_isRunningUnderDebugger()) juce_breakDebugger; JUCE_ANALYZER_NORETURN }
|
||||
#define jassertfalse MACRO_WITH_FORCED_SEMICOLON (juce_LogCurrentAssertion; if (juce::juce_isRunningUnderDebugger()) juce_breakDebugger; JUCE_ANALYZER_NORETURN)
|
||||
|
||||
//==============================================================================
|
||||
/** Platform-independent assertion macro.
|
||||
|
|
@ -117,19 +131,19 @@
|
|||
correct behaviour of your program!
|
||||
@see jassertfalse
|
||||
*/
|
||||
#define jassert(expression) { if (! (expression)) jassertfalse; }
|
||||
#define jassert(expression) MACRO_WITH_FORCED_SEMICOLON (if (! (expression)) jassertfalse;)
|
||||
|
||||
#else
|
||||
//==============================================================================
|
||||
// If debugging is disabled, these dummy debug and assertion macros are used..
|
||||
|
||||
#define DBG(dbgtext)
|
||||
#define jassertfalse { juce_LogCurrentAssertion }
|
||||
#define jassertfalse MACRO_WITH_FORCED_SEMICOLON (juce_LogCurrentAssertion)
|
||||
|
||||
#if JUCE_LOG_ASSERTIONS
|
||||
#define jassert(expression) { if (! (expression)) jassertfalse; }
|
||||
#define jassert(expression) MACRO_WITH_FORCED_SEMICOLON (if (! (expression)) jassertfalse;)
|
||||
#else
|
||||
#define jassert(a) {}
|
||||
#define jassert(a) MACRO_WITH_FORCED_SEMICOLON ()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -139,7 +153,7 @@
|
|||
namespace juce
|
||||
{
|
||||
template <bool b> struct JuceStaticAssert;
|
||||
template <> struct JuceStaticAssert <true> { static void dummy() {} };
|
||||
template <> struct JuceStaticAssert<true> { static void dummy() {} };
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue