From 40a77de88e8e8be988ec618ce0b500a3307666a1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Feb 2024 12:45:28 +0100 Subject: [PATCH] std-aux: workaround usage of _Pragma() inside nm_assert() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 62c1745f627b ('std-aux: suppress "-Wnonnull-compare" warning in nm_assert()') (cherry picked from commit e4b154e1b058aa1732821fb85db9b841d04ee691) --- src/libnm-std-aux/nm-std-aux.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 2575be4b69..bbd08dd77c 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -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; \ })