From 508352339aecc0010178e657f1ee41eb4f0a104c Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 6 Sep 2021 15:48:08 -0400 Subject: [PATCH] Fix false deprecation warnings on old GCC/MSVC Closes #2472 --- docs/reference/glib/glib-sections.txt | 1 + glib/gmacros.h | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 6533764e1..efb261bfd 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -738,6 +738,7 @@ G_HAVE_GNUC_VARARGS G_HAVE_ISO_VARARGS G_HAVE_GROWING_STACK G_VA_COPY_AS_ARRAY +GLIB_CANNOT_IGNORE_DEPRECATIONS GLIB_DEPRECATED GLIB_DEPRECATED_FOR GLIB_UNAVAILABLE diff --git a/glib/gmacros.h b/glib/gmacros.h index 27c2c48ac..7fc34d59d 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -720,6 +720,7 @@ #else #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS #define G_GNUC_END_IGNORE_DEPRECATIONS +#define GLIB_CANNOT_IGNORE_DEPRECATIONS #endif /** @@ -1090,7 +1091,14 @@ #define G_UNLIKELY(expr) (expr) #endif -#if G_GNUC_CHECK_VERSION(3, 1) || defined(__clang__) +/* GLIB_CANNOT_IGNORE_DEPRECATIONS is defined above for compilers that do not + * have a way to temporarily suppress deprecation warnings. In these cases, + * suppress the deprecated attribute altogether (otherwise a simple #include + * will emit a barrage of warnings). + */ +#if defined(GLIB_CANNOT_IGNORE_DEPRECATIONS) +#define G_DEPRECATED +#elif G_GNUC_CHECK_VERSION(3, 1) || defined(__clang__) #define G_DEPRECATED __attribute__((__deprecated__)) #elif defined(_MSC_VER) && (_MSC_VER >= 1300) #define G_DEPRECATED __declspec(deprecated) @@ -1098,7 +1106,9 @@ #define G_DEPRECATED #endif -#if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__) +#if defined(GLIB_CANNOT_IGNORE_DEPRECATIONS) +#define G_DEPRECATED_FOR(f) G_DEPRECATED +#elif G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__) #define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) #define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))