diff options
Diffstat (limited to 'src/libnm-std-aux/nm-std-aux.h')
| -rw-r--r-- | src/libnm-std-aux/nm-std-aux.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 3b39a019..bbd08dd7 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -83,6 +83,11 @@ /*****************************************************************************/ +#define NM_STRINGIFY_ARG(contents) #contents +#define NM_STRINGIFY(macro_or_string) NM_STRINGIFY_ARG(macro_or_string) + +/*****************************************************************************/ + #ifndef _NM_CC_SUPPORT_AUTO_TYPE #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) #define _NM_CC_SUPPORT_AUTO_TYPE 1 @@ -209,6 +214,48 @@ typedef uint64_t _nm_bitwise nm_be64_t; /*****************************************************************************/ +#if defined(__GNUC__) +#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(GCC diagnostic ignored warning) +#elif defined(__clang__) +#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(clang diagnostic ignored warning) +#endif + +/* you can only suppress a specific warning that the compiler + * understands. Otherwise you will get another compiler warning + * about invalid pragma option. + * It's not that bad however, because gcc and clang often have the + * same name for the same warning. */ + +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("GCC diagnostic push") +#define NM_PRAGMA_WARNING_DISABLE(warning) \ + NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO(warning)) +#define NM_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop") +#elif defined(__clang__) +#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("clang diagnostic push") +#define NM_PRAGMA_WARNING_DISABLE(warning) \ + NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \ + _Pragma(_NM_PRAGMA_WARNING_DO(warning)) +#define NM_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop") +#else +#define NM_PRAGMA_DIAGNOSTICS_PUSH +#define NM_PRAGMA_WARNING_DISABLE(warning) +#define NM_PRAGMA_WARNING_REENABLE +#endif + +/*****************************************************************************/ + +/* Seems gcc-12 has a tendency for false-positive -Wdangling-pointer warnings with + * g_error()'s `for(;;);`. See https://bugzilla.redhat.com/show_bug.cgi?id=2056613 . + * Work around, but only for the affected gcc 12.0.1. */ +#if defined(__GNUC__) && __GNUC__ == 12 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ <= 1 +#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_WARNING_DISABLE("-Wdangling-pointer") +#else +#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_DIAGNOSTICS_PUSH +#endif + +/*****************************************************************************/ + /* glib/C provides the following kind of assertions: * - assert() -- disable with NDEBUG * - g_return_if_fail() -- disable with G_DISABLE_CHECKS @@ -239,8 +286,18 @@ 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_assert_pragma_enter; \ + \ /* nm_assert() must do *nothing* of effect, except evaluating * @cond (0 or 1 times). * @@ -258,6 +315,9 @@ typedef uint64_t _nm_bitwise nm_be64_t; } else { \ _nm_assert_fail(#cond); \ } \ + \ + _nm_assert_pragma_leave; \ + \ 1; \ }) |