std-aux: mark _nm_assert_fail() as _nm_unreachable_code() with NDEBUG/G_DISABLE_ASSERT

This is useful, because it can avoid compiler warnings that are
emitted if the compiler things that the code can be reached.
_nm_assert_fail() can clearly never be reached (unless a bug happens).

When compiling we can disable assertion checks with
NDEBUG/G_DISABLE_ASSERT, but if we know that an assertion must not be
hit (for example with nm_assert_not_reached()) then we still want to
mark the path as unreachable, even if assert() does not abort the
process.
This commit is contained in:
Thomas Haller 2022-11-30 09:49:32 +01:00
parent 5ac5d7f8c3
commit 06931221b5
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 9 additions and 2 deletions

View file

@ -529,8 +529,13 @@ nm_str_realloc(char *str)
/* redefine assertions to use g_assert*() */
#undef _nm_assert_fail
#define _nm_assert_fail(msg) \
g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg)
#define _nm_assert_fail(msg) \
G_STMT_START \
{ \
g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \
_nm_unreachable_code(); \
} \
G_STMT_END
#undef _NM_ASSERT_FAIL_ENABLED
#ifndef G_DISABLE_ASSERT

View file

@ -246,6 +246,8 @@ _nm_assert_fail_internal(const char *assertion,
#define _nm_assert_fail(msg) \
do { \
_nm_unused const char *_msg = (msg); \
\
_nm_unreachable_code(); \
} while (0)
#endif