From a0973d0f947df731e9e182c8b03d6e351591f457 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 26 Oct 2017 14:59:40 -0700 Subject: Move the compiler version tests to ws_compiler_tests.h and use them elsewhere. While we're at it, sort some header file lists, and clean up white space. Change-Id: If737dda45334fedf1df7295d8719ad9381daf7a1 Reviewed-on: https://code.wireshark.org/review/24089 Reviewed-by: Guy Harris --- ws_diag_control.h | 58 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'ws_diag_control.h') diff --git a/ws_diag_control.h b/ws_diag_control.h index b2a4561f6f..428091addd 100644 --- a/ws_diag_control.h +++ b/ws_diag_control.h @@ -24,6 +24,8 @@ #ifndef __WS_DIAG_CONTROL_H__ #define __WS_DIAG_CONTROL_H__ +#include "ws_compiler_tests.h" + #ifdef __cplusplus extern "C" { #endif @@ -45,26 +47,35 @@ extern "C" { pragma clang diagnostic error/warning/ignored -Wxxx and pragma clang diagnostic push/pop were introduced in clang 2.8 */ -#if defined(__GNUC__) && !defined(__clang__) -# define gcc_version ((__GNUC__ * 1000) + (__GNUC_MINOR__ * 10)) -# if gcc_version >= 4080 - /* - * gcc version is >= 4.8.0. We can use "GCC diagnostic push/pop" *and* - * gcc supports "-Wpedantic". - */ -# 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 -#elif defined(__clang__) -# define clang_version ((__clang_major__ * 1000) + (__clang_minor__ * 10)) -# if clang_version >= 2080 - /* clang version is >= 2.8: 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 +#if !defined(__clang__) && WS_IS_AT_LEAST_GNUC_VERSION(4,8) + /* + * 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". + */ + #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) + /* + * 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) +#else + /* + * This is none of the above; we don't have any way to turn diagnostics + * on or off. + * + * XXX - you can do that in MSVC, but it's done differently; we'd + * have to have macros for *particular* diagnostics, using the + * warning flag for GCC and Clang and the error number for MSVC. + */ + #define DIAG_OFF(x) + #define DIAG_ON(x) #endif /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */ @@ -76,13 +87,6 @@ extern "C" { # define DIAG_ON_CLANG(x) #endif -#ifndef DIAG_OFF - /* no gcc or clang, or gcc version < 4.2.0, or clang version < 2.8: - we can't do anything */ -# define DIAG_OFF(x) -# define DIAG_ON(x) -#endif - /* * For dealing with APIs which are only deprecated in macOS (like the * OpenSSL and MIT/Heimdal Kerberos APIs). -- cgit v1.2.3