aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-10-26 19:00:20 -0700
committerGuy Harris <guy@alum.mit.edu>2017-10-27 02:01:03 +0000
commit42a9e893fb95f8f8612b52d4be00f7bbf6f7546b (patch)
treed65ab5e2a79b17c2104b6fa9b06b8edbf58deff4
parent1ceab868cd0c86e1a64e0b80150163a5b87b51ea (diff)
Clean up a bit.
If we're using Clang, use either _Pragma("clang diagnostic XXX") or nothing; don't use _Pragma("GCC diagnostic XXX"). If we're using something other than Clang that is, or claims to be, GCC, use _Pragma("GCC diagnostic XXX") or nothing. Explain why we're only using _Pragma("GCC diagnostic XXX") with GCC 4.8 or later, even though it's supported in GCC 4.2 and later, and even though 4.6 an later support _Pragma("GCC diagnostic {push,pop}"). Change-Id: I7a5f46ec419b945663d473cb4ae435ab7fdcf0ef Reviewed-on: https://code.wireshark.org/review/24096 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--ws_diag_control.h55
1 files changed, 31 insertions, 24 deletions
diff --git a/ws_diag_control.h b/ws_diag_control.h
index 428091addd..e7db8f5f1f 100644
--- a/ws_diag_control.h
+++ b/ws_diag_control.h
@@ -38,34 +38,41 @@ extern "C" {
#define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
#define DIAG_DO_PRAGMA(x) _Pragma (#x)
-/* check the gcc or clang version
-
- pragma GCC diagnostic error/warning/ignored -Wxxx was introduced
- in gcc 4.2.0
- pragma GCC diagnostic push/pop was introduced in gcc 4.6.0
-
- pragma clang diagnostic error/warning/ignored -Wxxx and
- pragma clang diagnostic push/pop were introduced in clang 2.8 */
-
-#if !defined(__clang__) && WS_IS_AT_LEAST_GNUC_VERSION(4,8)
+#if defined(__clang__)
/*
- * This is GCC, or a compiler that 1) claims to be GCC and 2) does
- * *not* claim to be Clang, and is claiming to be GCC version 4.8.0
- * or later.
- * We can use "GCC diagnostic push/pop" *and* gcc supports "-Wpedantic".
+ * Clang, so we'd use _Pragma("clang diagnostic XXX"), if it's
+ * supported.
*/
- #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
- #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
- #define DIAG_ON(x) DIAG_PRAGMA(pop)
-#elif WS_IS_AT_LEAST_CLANG_VERSION(2,8)
+ #if WS_IS_AT_LEAST_CLANG_VERSION(2,8)
+ /*
+ * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
+ * and "clang diagnostic push/pop".
+ */
+ #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
+ #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
+ #define DIAG_ON(x) DIAG_PRAGMA(pop)
+ #endif
+#elif defined(__GNUC__)
/*
- * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
- * and "clang diagnostic push/pop".
+ * GCC, or a compiler (other than Clang) that claims to be GCC.
+ * We assume that the compiler accepts _Pragma("GCC diagnostic xxx")
+ * even if it's only claiming to be GCC.
*/
- #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
- #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
- #define DIAG_ON(x) DIAG_PRAGMA(pop)
-#else
+ #if WS_IS_AT_LEAST_GNUC_VERSION(4,8)
+ /*
+ * This is GCC 4.8 or later, or a compiler claiming to be that.
+ * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
+ * and "GCC diagnostic push/pop" (introduced in 4.6), *and* gcc
+ * supports "-Wpedantic" (introduced in 4.8), allowing us to
+ * turn off pedantic warnings with DIAG_OFF().
+ */
+ #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
+ #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
+ #define DIAG_ON(x) DIAG_PRAGMA(pop)
+ #endif
+#endif
+
+#ifndef DIAG_OFF
/*
* This is none of the above; we don't have any way to turn diagnostics
* on or off.