[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add support for temporarily suppressing a warning



commit 0279e4847352111254503159685487e5e1f58681
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri May 27 11:23:52 2016 -0400

    Add support for temporarily suppressing a warning
    
    There are a few places where we want to disable a warning: for
    example, when it's impossible to call a legacy API without
    triggering it, or when it's impossible to include an external header
    without triggering it.
    
    This pile of macros uses GCC's c99 _Pragma support, plus the usual
    macro trickery, to enable and disable warnings.
---
 src/common/compat.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/common/compat.h b/src/common/compat.h
index b6ee410..6f102be 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -82,6 +82,44 @@
 #define CHECK_SCANF(formatIdx, firstArg)
 #endif
 
+/* What GCC do we have? */
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+#else
+#define GCC_VERSION 0
+#endif
+
+/* Temporarily enable and disable warnings. */
+#ifdef __GNUC__
+#  define PRAGMA_STRINGIFY_(s) #s
+#  define PRAGMA_JOIN_STRINGIFY_(a,b) PRAGMA_STRINGIFY_(a ## b)
+/* Support for macro-generated pragmas (c99) */
+#  define PRAGMA_(x) _Pragma (#x)
+#  ifdef __clang__
+#    define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(clang diagnostic x)
+#  else
+#    define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(GCC diagnostic x)
+#  endif
+#  if defined(__clang__) || GCC_VERSION >= 406
+/* we have push/pop support */
+#    define DISABLE_GCC_WARNING(warning) \
+          PRAGMA_DIAGNOSTIC_(push) \
+          PRAGMA_DIAGNOSTIC_(ignored PRAGMA_JOIN_STRINGIFY_(-W,warning))
+#    define ENABLE_GCC_WARNING(warning) \
+          PRAGMA_DIAGNOSTIC_(pop)
+#  else
+/* older version of gcc: no push/pop support. */
+#    define DISABLE_GCC_WARNING(warning) \
+         PRAGMA_DIAGNOSTIC_(ignored PRAGMA_JOIN_STRINGIFY_(-W,warning))
+#    define ENABLE_GCC_WARNING(warning) \
+         PRAGMA_DIAGNOSTIC_(warning PRAGMA_JOIN_STRINGIFY_(-W,warning))
+#  endif
+#else /* ifdef __GNUC__ */
+/* not gcc at all */
+# define DISABLE_GCC_WARNING(warning)
+# define ENABLE_GCC_WARNING(warning)
+#endif
+
 /* inline is __inline on windows. */
 #ifdef _WIN32
 #define inline __inline



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits