diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 414c6659b3..3bb2e1bb09 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -5426,6 +5426,15 @@ test_nm_set_out (void) call_count = 0; NM_SET_OUT (p_val, do_test_nm_set_out_called (&call_count)); g_assert_cmpint (call_count, ==, 0); + + /* test that we successfully re-defined _G_BOOLEAN_EXPR() */ +#define _T1(a) \ + ({ \ + g_assert (a > 5); \ + a; \ + }) + g_assert (_T1 (3) > 1); +#undef _T1 } /*****************************************************************************/ diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index c072eef61a..0b99b0bf56 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -731,6 +731,33 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) { #define false 0 #endif + +#ifdef _G_BOOLEAN_EXPR +/* g_assert() uses G_LIKELY(), which in turn uses _G_BOOLEAN_EXPR(). + * As glib's implementation uses a local variable _g_boolean_var_, + * we cannot do + * g_assert (some_macro ()); + * where some_macro() itself expands to ({g_assert(); ...}). + * In other words, you cannot have a g_assert() inside a g_assert() + * without getting a -Werror=shadow failure. + * + * Workaround that by re-defining _G_BOOLEAN_EXPR() + **/ +#undef _G_BOOLEAN_EXPR +#define __NM_G_BOOLEAN_EXPR_IMPL(v, expr) \ + ({ \ + int NM_UNIQ_T(V, v); \ + \ + if (expr) \ + NM_UNIQ_T(V, v) = 1; \ + else \ + NM_UNIQ_T(V, v) = 0; \ + NM_UNIQ_T(V, v); \ + }) +#define _G_BOOLEAN_EXPR(expr) __NM_G_BOOLEAN_EXPR_IMPL (NM_UNIQ, expr) +#endif + + /*****************************************************************************/ #endif /* __NM_MACROS_INTERNAL_H__ */