Add wxASSERT_MSG_AT() and wxFAIL_MSG_AT() macros.

These macros are useful for functions called from other macros to allow
pretending that an assert inside such function actually happens at the point
in the sources where the macro itself appears.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2015-01-24 22:08:41 +00:00
parent 54d2b38643
commit 3dff63b563
3 changed files with 50 additions and 6 deletions

View File

@@ -282,34 +282,44 @@ extern WXDLLIMPEXP_BASE void wxOnAssert(const char *file,
// reasons (if we changed its return type, we'd need to change wxApp::
// OnAssertFailure() too which would break user code overriding it), hence
// the need for the ugly global flag.
#define wxASSERT_MSG(cond, msg) \
#define wxASSERT_MSG_AT(cond, msg, file, line, func) \
wxSTATEMENT_MACRO_BEGIN \
if ( wxTheAssertHandler && !(cond) && \
(wxOnAssert(__FILE__, __LINE__, __WXFUNCTION__, \
#cond, msg), wxTrapInAssert) ) \
(wxOnAssert(file, line, func, #cond, msg), \
wxTrapInAssert) ) \
{ \
wxTrapInAssert = false; \
wxTrap(); \
} \
wxSTATEMENT_MACRO_END
// A version asserting at the current location.
#define wxASSERT_MSG(cond, msg) \
wxASSERT_MSG_AT(cond, msg, __FILE__, __LINE__, __WXFUNCTION__)
// a version without any additional message, don't use unless condition
// itself is fully self-explanatory
#define wxASSERT(cond) wxASSERT_MSG(cond, (const char*)NULL)
// wxFAIL is a special form of assert: it always triggers (and so is
// usually used in normally unreachable code)
#define wxFAIL_COND_MSG(cond, msg) \
#define wxFAIL_COND_MSG_AT(cond, msg, file, line, func) \
wxSTATEMENT_MACRO_BEGIN \
if ( wxTheAssertHandler && \
(wxOnAssert(__FILE__, __LINE__, __WXFUNCTION__, \
cond, msg), wxTrapInAssert) ) \
(wxOnAssert(file, line, func, #cond, msg), \
wxTrapInAssert) ) \
{ \
wxTrapInAssert = false; \
wxTrap(); \
} \
wxSTATEMENT_MACRO_END
#define wxFAIL_MSG_AT(msg, file, line, func) \
wxFAIL_COND_MSG_AT("Assert failure", msg, file, line, func)
#define wxFAIL_COND_MSG(cond, msg) \
wxFAIL_COND_MSG_AT(cond, msg, __FILE__, __LINE__, __WXFUNCTION__)
#define wxFAIL_MSG(msg) wxFAIL_COND_MSG("Assert failure", msg)
#define wxFAIL wxFAIL_MSG((const char*)NULL)
#else // !wxDEBUG_LEVEL