add GCC_DIAG_IGNORE(), GCC_DIAG_RESTORE macros
authorDavid Mitchell <davem@iabyn.com>
Wed, 27 Nov 2013 16:56:59 +0000 (16:56 +0000)
committerDavid Mitchell <davem@iabyn.com>
Thu, 28 Nov 2013 17:03:49 +0000 (17:03 +0000)
These allow you to temporarily disable a specific gcc or clang warning;
e.g.

    GCC_DIAG_IGNORE(-Wmultichar);
    char b = 'ab';
    GCC_DIAG_RESTORE;

perl.h

diff --git a/perl.h b/perl.h
index fccf4ba..b73c1a7 100644 (file)
--- a/perl.h
+++ b/perl.h
 #  define PERL_UNUSED_CONTEXT
 #endif
 
+/* on gcc (and clang), specify that a warning should be temporarily
+ * ignored; e.g.
+ *
+ *    GCC_DIAG_IGNORE(-Wmultichar);
+ *    char b = 'ab';
+ *    GCC_DIAG_RESTORE;
+ *
+ * based on http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
+ *
+ * Note that "pragma GCC diagnostic push/pop" was added in GCC 4.6, Mar 2011;
+ * clang only pretends to be GCC 4.2, but still supports push/pop.
+ */
+
+#if defined(__clang) || \
+       (defined( __GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402)
+#  define GCC_DIAG_DO_PRAGMA_(x) _Pragma (#x)
+
+#  define GCC_DIAG_IGNORE(x) _Pragma("GCC diagnostic push") \
+                             GCC_DIAG_DO_PRAGMA_(GCC diagnostic ignored #x)
+#  define GCC_DIAG_RESTORE   _Pragma("GCC diagnostic pop")
+#else
+#  define GCC_DIAG_IGNORE(w)
+#  define GCC_DIAG_RESTORE
+#endif
+
+
 #define NOOP /*EMPTY*/(void)0
 /* cea2e8a9dd23747f accidentally lost the comment originally from the first
    check in of thread.h, explaining why we need dNOOP at all:  */