glib-aux: add NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER macro for workaround

New gcc-12.0.1-0.8.fc36 on Fedora rawhide likes to emit false
"-Wdangling-pointer" warnings with some g_error() uses. It seems
related to g_error()'s `for(;;) ;`.

As workaround, add a macro to suppress the warning.
But only do that for gcc-12. This bug hopefully gets fixed
and we don't want to suppress useful warnings too eagerly.

https://bugzilla.redhat.com/show_bug.cgi?id=2056613
This commit is contained in:
Thomas Haller 2022-02-18 20:21:46 +01:00
parent cc28aac0de
commit 445dcd9d9b
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -202,6 +202,18 @@ _nm_auto_freev(gpointer ptr)
/*****************************************************************************/
/* Seems gcc-12 has a tendency for false-positive -Wdangling-pointer warnings with
* g_error()'s `for(;;);`.
*
* Work around that, but it's only for gcc 12 (for now). */
#if defined(__GNUC__) && __GNUC__ == 12
#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
/*****************************************************************************/
/**
* NM_G_ERROR_MSG:
* @error: (allow-none): the #GError instance