mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-28 06:56:16 +01:00
Merge branch 'mcatanzaro/g_assert_cpp' into 'master'
Add separate definitions of g_assert_[non]null() for C++ See merge request GNOME/glib!568
This commit is contained in:
commit
193cc66919
@ -124,6 +124,19 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
"'" #expr "' should be FALSE"); \
|
"'" #expr "' should be FALSE"); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
|
/* Use nullptr in C++ to catch misuse of these macros. */
|
||||||
|
#if defined(__cplusplus) && __cplusplus >= 201100L
|
||||||
|
#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == nullptr) ; else \
|
||||||
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
"'" #expr "' should be nullptr"); \
|
||||||
|
} G_STMT_END
|
||||||
|
#define g_assert_nonnull(expr) G_STMT_START { \
|
||||||
|
if G_LIKELY ((expr) != nullptr) ; else \
|
||||||
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
"'" #expr "' should not be nullptr"); \
|
||||||
|
} G_STMT_END
|
||||||
|
#else /* not C++ */
|
||||||
#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == NULL) ; else \
|
#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == NULL) ; else \
|
||||||
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
"'" #expr "' should be NULL"); \
|
"'" #expr "' should be NULL"); \
|
||||||
@ -133,6 +146,8 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
"'" #expr "' should not be NULL"); \
|
"'" #expr "' should not be NULL"); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef G_DISABLE_ASSERT
|
#ifdef G_DISABLE_ASSERT
|
||||||
#define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
|
#define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
|
||||||
#define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
|
#define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
|
||||||
|
Loading…
Reference in New Issue
Block a user