[Automatic update for 2018-02-04]
[metze/wireshark/wip.git] / ws_diag_control.h
1 /* ws_diag_control.h
2  * Turn compiler diagnostic messages on and off.
3  *
4  * From FreeRADIUS build.h.
5  *
6  * @copyright 2013 The FreeRADIUS server project
7  *
8  * That project is covered by the GPLv2, so:
9  *
10  * SPDX-License-Identifier: GPL-2.0+
11  */
12
13 #ifndef __WS_DIAG_CONTROL_H__
14 #define __WS_DIAG_CONTROL_H__
15
16 #include "ws_compiler_tests.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define XSTRINGIFY(x) #x
23
24 /*
25  *      Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
26  */
27 #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
28 #define DIAG_DO_PRAGMA(x) _Pragma (#x)
29
30 #if defined(__clang__)
31   /*
32    * Clang, so we'd use _Pragma("clang diagnostic XXX"), if it's
33    * supported.
34    */
35   #if WS_IS_AT_LEAST_CLANG_VERSION(2,8)
36     /*
37      * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
38      * and "clang diagnostic push/pop".
39      */
40     #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
41     #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
42     #define DIAG_ON(x) DIAG_PRAGMA(pop)
43   #endif
44 #elif defined(__GNUC__)
45   /*
46    * GCC, or a compiler (other than Clang) that claims to be GCC.
47    * We assume that the compiler accepts _Pragma("GCC diagnostic xxx")
48    * even if it's only claiming to be GCC.
49    */
50   #if WS_IS_AT_LEAST_GNUC_VERSION(4,8)
51     /*
52      * This is GCC 4.8 or later, or a compiler claiming to be that.
53      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
54      * and "GCC diagnostic push/pop" (introduced in 4.6), *and* gcc
55      * supports "-Wpedantic" (introduced in 4.8), allowing us to
56      * turn off pedantic warnings with DIAG_OFF().
57      */
58     #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
59     #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
60     #define DIAG_ON(x) DIAG_PRAGMA(pop)
61   #endif
62 #endif
63
64 #ifndef DIAG_OFF
65   /*
66    * This is none of the above; we don't have any way to turn diagnostics
67    * on or off.
68    *
69    * XXX - you can do that in MSVC, but it's done differently; we'd
70    * have to have macros for *particular* diagnostics, using the
71    * warning flag for GCC and Clang and the error number for MSVC.
72    */
73   #define DIAG_OFF(x)
74   #define DIAG_ON(x)
75 #endif
76
77 /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */
78 #ifdef __clang__
79 #  define DIAG_OFF_CLANG(x) DIAG_OFF(x)
80 #  define DIAG_ON_CLANG(x)  DIAG_ON(x)
81 #else
82 #  define DIAG_OFF_CLANG(x)
83 #  define DIAG_ON_CLANG(x)
84 #endif
85
86 /*
87  *      For dealing with APIs which are only deprecated in macOS (like the
88  *      OpenSSL and MIT/Heimdal Kerberos APIs).
89  *
90  *      Dear Apple: this is a cross-platform program, and we're not
91  *      going to use your Shiny New Frameworks on macOS unless there's
92  *      a sufficiently clear benefit to make it worth our while to have
93  *      both macOS and non-macOS versions of the code.
94  */
95 #ifdef __APPLE__
96 #  define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
97 #  define USES_APPLE_RST DIAG_ON(deprecated-declarations)
98 #else
99 #  define USES_APPLE_DEPRECATED_API
100 #  define USES_APPLE_RST
101 #endif
102
103 #ifdef __cplusplus
104 }
105 #endif
106 #endif /* __WS_DIAG_CONTROL_H__ */