std-aux: workaround usage of _Pragma() inside nm_assert()

Older gcc versions don't like this. The _Pragam() itself is to workaround a
-Wnonnull-compare warning with gcc 14.

After all, we use compiler warning extensively. They are our linters and have
necessarily false positives. To make them usable across a wide range of
compilers, is a constant effort.

Here is another one.

The error:

  ./src/libnm-std-aux/nm-std-aux.h: In function ‘nm_utils_addr_family_other’:
  ./src/libnm-std-aux/nm-std-aux.h:230:36: error: expected expression before ‘#pragma’
    230 | #define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("GCC diagnostic push")
        |                                    ^~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:232:5: note: in expansion of macro ‘NM_PRAGMA_DIAGNOSTICS_PUSH’
    232 |     NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO(warning))
        |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:291:9: note: in expansion of macro ‘NM_PRAGMA_WARNING_DISABLE’
    291 |         NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare");                \
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:953:9: note: in expansion of macro ‘nm_assert’
    953 |         nm_assert(true || NM_UNIQ_T(xx, uniq) == (x));                    \
        |         ^~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:961:27: note: in expansion of macro ‘_NM_IN_SET’
    961 | #define NM_IN_SET(x, ...) _NM_IN_SET(NM_UNIQ, ||, typeof(x), x, __VA_ARGS__)
        |                           ^~~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:1493:15: note: in expansion of macro ‘NM_IN_SET’
   1493 |     nm_assert(NM_IN_SET((addr_family), NM_AF_INET, NM_AF_INET6))
        |               ^~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:1502:9: note: in expansion of macro ‘nm_assert_addr_family’
   1502 |         nm_assert_addr_family(NM_UNIQ_T(_addr_family, uniq));    \
        |         ^~~~~~~~~~~~~~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:1510:33: note: in expansion of macro ‘_NM_IS_IPv4’
   1510 | #define NM_IS_IPv4(addr_family) _NM_IS_IPv4(NM_UNIQ, addr_family)
        |                                 ^~~~~~~~~~~
  ./src/libnm-std-aux/nm-std-aux.h:1515:12: note: in expansion of macro ‘NM_IS_IPv4’
   1515 |     return NM_IS_IPv4(addr_family) ? NM_AF_INET6 : NM_AF_INET;
        |            ^~~~~~~~~~

Fixes: 62c1745f62 ('std-aux: suppress "-Wnonnull-compare" warning in nm_assert()')
(cherry picked from commit e4b154e1b0)
This commit is contained in:
Thomas Haller 2024-02-07 12:45:28 +01:00 committed by Íñigo Huguet
parent 926351d031
commit 40a77de88e

View file

@ -286,9 +286,17 @@ typedef uint64_t _nm_bitwise nm_be64_t;
#define NM_MORE_ASSERTS_EFFECTIVE (_NM_ASSERT_FAIL_ENABLED ? NM_MORE_ASSERTS : 0)
#if defined(__GNUC__) && __GNUC__ >= 12
#define _nm_assert_pragma_enter NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare")
#define _nm_assert_pragma_leave NM_PRAGMA_WARNING_REENABLE
#else
#define _nm_assert_pragma_enter
#define _nm_assert_pragma_leave
#endif
#define nm_assert(cond) \
({ \
NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare"); \
_nm_assert_pragma_enter; \
\
/* nm_assert() must do *nothing* of effect, except evaluating
* @cond (0 or 1 times).
@ -308,7 +316,7 @@ typedef uint64_t _nm_bitwise nm_be64_t;
_nm_assert_fail(#cond); \
} \
\
NM_PRAGMA_WARNING_REENABLE; \
_nm_assert_pragma_leave; \
\
1; \
})