Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS
authorDan Winship <danw@gnome.org>
Fri, 10 Feb 2012 13:49:17 +0000 (08:49 -0500)
committerDan Winship <danw@gnome.org>
Wed, 15 Feb 2012 14:54:38 +0000 (09:54 -0500)
Add new macros to disable -Wdeprecated-declarations around a piece of
code, using the C99 (and GNU89) _Pragma() operator. Replace the
existing use of #pragma for this in gio, and suppress the warnings in
gvaluearray.c as well.

https://bugzilla.gnome.org/show_bug.cgi?id=669671

docs/reference/glib/glib-sections.txt
gio/gdesktopappinfo.c
gio/giomodule.c
glib/docs.c
glib/gmacros.h
gobject/gvaluearray.c

index 0d87c4b..1f829f0 100644 (file)
@@ -336,6 +336,8 @@ G_GNUC_ALLOC_SIZE
 G_GNUC_ALLOC_SIZE2
 G_GNUC_DEPRECATED
 G_GNUC_DEPRECATED_FOR
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+G_GNUC_END_IGNORE_DEPRECATIONS
 G_GNUC_NORETURN
 G_GNUC_UNUSED
 G_GNUC_PRINTF
index 5980c3f..449c114 100644 (file)
@@ -3352,6 +3352,8 @@ get_all_desktop_entries_for_mime_type (const char  *base_mime_type,
 
 /* GDesktopAppInfoLookup interface: */
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
 typedef GDesktopAppInfoLookupIface GDesktopAppInfoLookupInterface;
 G_DEFINE_INTERFACE (GDesktopAppInfoLookup, g_desktop_app_info_lookup, G_TYPE_OBJECT)
 
@@ -3378,8 +3380,6 @@ g_desktop_app_info_lookup_default_init (GDesktopAppInfoLookupInterface *iface)
  *
  * Deprecated: The #GDesktopAppInfoLookup interface is deprecated and unused by gio.
  */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 GAppInfo *
 g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup,
                                                      const char            *uri_scheme)
@@ -3392,4 +3392,5 @@ g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *loo
 
   return (* iface->get_default_for_uri_scheme) (lookup, uri_scheme);
 }
-#pragma GCC diagnostic pop
+
+G_GNUC_END_IGNORE_DEPRECATIONS
index 9ccc3e3..02c2db6 100644 (file)
@@ -809,8 +809,6 @@ DllMain (HINSTANCE hinstDLL,
 
 #endif
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 void
 _g_io_modules_ensure_extension_points_registered (void)
 {
@@ -826,7 +824,9 @@ _g_io_modules_ensure_extension_points_registered (void)
 #ifdef G_OS_UNIX
 #if !GLIB_CHECK_VERSION (3, 0, 0)
       ep = g_io_extension_point_register (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME);
+      G_GNUC_BEGIN_IGNORE_DEPRECATIONS
       g_io_extension_point_set_required_type (ep, G_TYPE_DESKTOP_APP_INFO_LOOKUP);
+      G_GNUC_END_IGNORE_DEPRECATIONS
 #endif
 #endif
       
@@ -863,7 +863,6 @@ _g_io_modules_ensure_extension_points_registered (void)
   
   G_UNLOCK (registered_extensions);
 }
-#pragma GCC diagnostic pop
 
 void
 _g_io_modules_ensure_loaded (void)
index 97d41cd..f680ae0 100644 (file)
  */
 
 /**
+ * G_GNUC_BEGIN_IGNORE_DEPRECATIONS:
+ *
+ * Tells <command>gcc</command> (if it is a new enough version) to
+ * temporarily stop emitting warnings when functions marked with
+ * %G_GNUC_DEPRECATED or %G_GNUC_DEPRECATED_FOR are called. This is
+ * useful for when you have one deprecated function calling another
+ * one, or when you still have regression tests for deprecated
+ * functions.
+ *
+ * Use %G_GNUC_END_IGNORE_DEPRECATIONS to begin warning again. (If you
+ * are not compiling with <literal>-Wdeprecated-declarations</literal>
+ * then neither macro has any effect.)
+ *
+ * This macro can be used either inside or outside of a function body,
+ * but must appear on a line by itself.
+ *
+ * Since: 2.32
+ */
+
+/**
+ * G_GNUC_END_IGNORE_DEPRECATIONS:
+ *
+ * Undoes the effect of %G_GNUC_BEGIN_IGNORE_DEPRECATIONS, telling
+ * <command>gcc</command> to begin outputting warnings again
+ * (assuming those warnings had been enabled to begin with).
+ *
+ * This macro can be used either inside or outside of a function body,
+ * but must appear on a line by itself.
+ *
+ * Since: 2.32
+ */
+
+/**
  * G_GNUC_NORETURN:
  *
  * Expands to the GNU C <literal>noreturn</literal> function attribute
index 2b340cb..e07610c 100644 (file)
 #define G_GNUC_DEPRECATED_FOR(f)        G_GNUC_DEPRECATED
 #endif /* __GNUC__ */
 
+#if    __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS               \
+  _Pragma ("GCC diagnostic push")                      \
+  _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define G_GNUC_END_IGNORE_DEPRECATIONS                 \
+  _Pragma ("GCC diagnostic pop")
+#else
+#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#define G_GNUC_END_IGNORE_DEPRECATIONS
+#endif
+
 #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 #  define G_GNUC_MAY_ALIAS __attribute__((may_alias))
 #else
index 39c9c01..db6c719 100644 (file)
@@ -228,7 +228,9 @@ g_value_array_prepend (GValueArray  *value_array,
 {
   g_return_val_if_fail (value_array != NULL, NULL);
 
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   return g_value_array_insert (value_array, 0, value);
+  G_GNUC_END_IGNORE_DEPRECATIONS
 }
 
 /**
@@ -249,7 +251,9 @@ g_value_array_append (GValueArray  *value_array,
 {
   g_return_val_if_fail (value_array != NULL, NULL);
 
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   return g_value_array_insert (value_array, value_array->n_values, value);
+  G_GNUC_END_IGNORE_DEPRECATIONS
 }
 
 /**