summaryrefslogtreecommitdiff
path: root/src/common/compat.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-05-27 11:23:52 -0400
committerNick Mathewson <nickm@torproject.org>2016-05-27 11:23:52 -0400
commit0279e4847352111254503159685487e5e1f58681 (patch)
treeba6145abf0a24f9e6268673cabd6b72cd2fdd90c /src/common/compat.h
parenta0dd8360983e8df41424694f4708ffa6f03f65a1 (diff)
downloadtor-0279e4847352111254503159685487e5e1f58681.tar.gz
tor-0279e4847352111254503159685487e5e1f58681.zip
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.
Diffstat (limited to 'src/common/compat.h')
-rw-r--r--src/common/compat.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index b6ee4106db..6f102becc2 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