From 9801f91a8eacec32950b0bf094aba45e891f63e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 3 Dec 2020 11:33:29 +0000 Subject: [PATCH] util: squelch G_DEFINE_TYPE volatile warnings with GCC 11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this previous commit: commit 65491a2dfe00bfcf9f09a8d6eab60234b56c8cc4 Author: Martin Kletzander Date: Thu Nov 12 13:58:53 2020 +0100 Do not disable incompatible-pointer-types-discards-qualifiers We selectively rewrite G_DEFINE_TYPE to avoid warnings about mismatched volatile/non-volatile pointers that appeared with CLang when using GLib2 >= 2.67 We have now just hit the reverse problem, GCC >= 11 has started warning about mismatched volatile/non-volatile pointers but only with GLib2 < 2.67. The new GLib2 avoids the warning, as does older GCC. Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrangé --- src/util/glibcompat.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 457f6ba797..6463c4179a 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -22,7 +22,10 @@ #include #include -#if defined(__clang__) && GLIB_CHECK_VERSION(2, 67, 0) +#if GLIB_CHECK_VERSION(2, 67, 0) + +# if defined(__clang__) + /* * Clang detects (valid) issue in G_DEFINE_TYPE and derivatives starting with * glib >= 2.67.0. See https://gitlab.gnome.org/GNOME/glib/-/issues/600 @@ -34,16 +37,36 @@ * is defined in glib (with a very low probability of being changed thanks to a * comment above it). */ -# undef _G_DEFINE_TYPE_EXTENDED_BEGIN +# undef _G_DEFINE_TYPE_EXTENDED_BEGIN -# define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ +# define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types-discards-qualifiers\"") \ _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \ _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \ _Pragma("GCC diagnostic pop") -#endif /* __clang__ */ +# endif /* __clang__ */ + +#else /* GLib < 2.67.0 */ + +/* + * ...meanwhile GCC >= 11 has started issuing warnings about volatile + * from the old G_DEFINE_TYPE macro impl. IOW the new macros impls fixed + * new GCC, but broke CLang + */ +# if !defined(__clang__) && __GNUC_PREREQ (11, 0) +# undef _G_DEFINE_TYPE_EXTENDED_BEGIN + +# define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"") \ + _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \ + _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \ + _Pragma("GCC diagnostic pop") +# endif /* !clang && GCC >= 11.0 */ + +#endif /* GLib < 2.67.0 */ gchar * vir_g_canonicalize_filename(const gchar *filename, const gchar *relative_to);