dcerpc-netlogon: split out find_tmp_netlogon_auth_vars()
[wireshark-sm.git] / include / ws_diag_control.h
blob4764450b7a6b9e117ad9ab47aed5d1620710f914
1 /* ws_diag_control.h
2 * Turn compiler diagnostic messages on and off.
4 * From FreeRADIUS build.h.
6 * @copyright 2013 The FreeRADIUS server project
8 * That project is covered by the GPLv2, so:
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __WS_DIAG_CONTROL_H__
14 #define __WS_DIAG_CONTROL_H__
16 #include "ws_compiler_tests.h"
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
22 #define XSTRINGIFY(x) #x
25 * Macros for controlling warnings in various compilers.
27 #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
30 * XXX - this is only for GCC or GCC-compatible compilers, and we only use
31 * it to have a macro that takes a warning as an argument and turns it
32 * off in the appropriate fashion for Clang and GCC; it should only be
33 * used internally in this header.
35 #define DIAG_DO_PRAGMA(x) _Pragma (#x)
37 #if defined(__clang__)
39 * Clang, so we'd use _Pragma("clang diagnostic XXX"), if it's
40 * supported.
42 #if WS_IS_AT_LEAST_CLANG_VERSION(2,8)
44 * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
45 * and "clang diagnostic push/pop".
47 #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
48 #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
49 #define DIAG_WARN(x) DIAG_PRAGMA(push) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
50 #define DIAG_ON(x) DIAG_PRAGMA(pop)
51 #endif
54 * Not all versions of Clang understand -Wpedantic. Clang 4.0 appears
55 * to be the first version to do so.
57 #if WS_IS_AT_LEAST_CLANG_VERSION(4,0)
58 #define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic)
59 #define DIAG_ON_PEDANTIC DIAG_ON(pedantic)
60 #else
61 #define DIAG_OFF_PEDANTIC
62 #define DIAG_ON_PEDANTIC
63 #endif
66 * Do any pre-5.0 versions of Clang understand -Winitializer-overrides?
68 #if WS_IS_AT_LEAST_CLANG_VERSION(4,0)
69 #define DIAG_OFF_INIT_TWICE DIAG_OFF(initializer-overrides)
70 #define DIAG_ON_INIT_TWICE DIAG_ON(initializer-overrides)
71 #else
72 #define DIAG_OFF_INIT_TWICE
73 #define DIAG_ON_INIT_TWICE
74 #endif
75 #elif defined(__GNUC__)
77 * GCC, or a compiler (other than Clang) that claims to be GCC.
78 * We assume that the compiler accepts _Pragma("GCC diagnostic xxx")
79 * even if it's only claiming to be GCC.
81 #if WS_IS_AT_LEAST_GNUC_VERSION(4,8)
83 * This is GCC 4.8 or later, or a compiler claiming to be that.
84 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
85 * and "GCC diagnostic push/pop" (introduced in 4.6), *and* gcc
86 * supports "-Wpedantic" (introduced in 4.8), allowing us to
87 * turn off pedantic warnings with DIAG_OFF().
89 #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
90 #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
91 #define DIAG_WARN(x) DIAG_PRAGMA(push) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
92 #define DIAG_ON(x) DIAG_PRAGMA(pop)
95 * We assume GCC 4.8 and later understand -Wpedantic.
97 #define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic)
98 #define DIAG_ON_PEDANTIC DIAG_ON(pedantic)
101 * GCC 4.2 and later understand -Woverride-init.
103 #define DIAG_OFF_INIT_TWICE DIAG_OFF(override-init)
104 #define DIAG_ON_INIT_TWICE DIAG_ON(override-init)
105 #else
106 #define DIAG_OFF_PEDANTIC
107 #define DIAG_ON_PEDANTIC
109 #define DIAG_OFF_INIT_TWICE
110 #define DIAG_ON_INIT_TWICE
111 #endif
112 #endif
114 #ifndef DIAG_OFF
116 * This is none of the above; we don't have any way to turn diagnostics
117 * on or off.
119 * XXX - you can do that in MSVC, but it's done differently; we'd
120 * have to have macros for *particular* diagnostics, using the
121 * warning flag for GCC and Clang and the error number for MSVC.
123 #define DIAG_OFF(x)
124 #define DIAG_WARN(x)
125 #define DIAG_ON(x)
126 #define DIAG_OFF_PEDANTIC
127 #define DIAG_ON_PEDANTIC
128 #define DIAG_OFF_INIT_TWICE
129 #define DIAG_ON_INIT_TWICE
130 #endif
132 /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */
133 #ifdef __clang__
134 # define DIAG_OFF_CLANG(x) DIAG_OFF(x)
135 # define DIAG_WARN_CLANG(x) DIAG_WARN(x)
136 # define DIAG_ON_CLANG(x) DIAG_ON(x)
137 #else
138 # define DIAG_OFF_CLANG(x)
139 # define DIAG_ON_CLANG(x)
140 #endif
143 * Suppress complaints about narrowing conversations and about signed vs.
144 * unsigned comparison.
146 * XXX - this is done solely to squelch complaints from code generated
147 * by Flex, but newer versions of Flex might fix the code; can we
148 * check the version of Flex and suppress only the checks that code
149 * generated by that version of Flex triggers?
151 #if defined(_MSC_VER)
153 * Suppress:
155 * warning C4018: signed/unsigned mismatch
156 * warning C4244: 'initializing' : conversion from '__int64' to 'int', possible loss of data
157 * warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
159 * as well as Visual Studio Code Analyzer warnings:
161 * warning C6011: Dereferencing NULL pointer
162 * warning C6308: 'realloc' might return null pointer
163 * warning C6386: Buffer overrun
164 * warning C6387: 'XXX' could be '0'
165 * warning C28182: Dereferencing NULL pointer
167 #define DIAG_OFF_FLEX() \
168 __pragma(warning(push)) \
169 __pragma(warning(disable:4018)) \
170 __pragma(warning(disable:4244)) \
171 __pragma(warning(disable:4267)) \
172 __pragma(warning(disable:6011)) \
173 __pragma(warning(disable:6308)) \
174 __pragma(warning(disable:6386)) \
175 __pragma(warning(disable:6387)) \
176 __pragma(warning(disable:28182))
177 #define DIAG_ON_FLEX() \
178 __pragma(warning(pop))
179 #else
181 * Suppress:
183 * -Wsigned-compare warnings
184 * -Wshorten-64-to-32 warnings, if the compiler *has* -Wshorten-64-to-32
185 * -Wunreachable-code warnings
186 * The version of Flex in the macOS Intel build bots triggers documentation warnings.
187 * -Wdocumentation
189 * We use DIAG_OFF() and DIAG_ON(), so we only use features that the
190 * compiler supports.
192 * We disable -Wshorten-64-to-32 if we're using Clang, or if __APPLE__
193 * is defined; that option was originally added to an Apple version of
194 * GCC, and at least some versions of Clang support it - given that
195 * the Clang work started at Apple, it may be in all versions of Clang.
197 * (Does no version of GCC or Clang support the same generic "you're
198 * narrowing a value, and you didn't throw in a cast to assert that
199 * you know what you're doing" warning that MSVC does?)
201 #if defined(__clang__) || defined(__APPLE__)
202 #define DIAG_OFF_FLEX() \
203 DIAG_OFF(sign-compare) \
204 DIAG_OFF(unused-parameter) \
205 DIAG_OFF(shorten-64-to-32) \
206 DIAG_OFF(unreachable-code) \
207 DIAG_OFF(documentation)
208 #define DIAG_ON_FLEX() \
209 DIAG_ON(documentation) \
210 DIAG_ON(unreachable-code) \
211 DIAG_ON(shorten-64-to-32) \
212 DIAG_ON(unused-parameter) \
213 DIAG_ON(sign-compare)
214 #else
215 #define DIAG_OFF_FLEX() \
216 DIAG_OFF(sign-compare) \
217 DIAG_OFF(unused-parameter)
218 #define DIAG_ON_FLEX() \
219 DIAG_ON(unused-parameter) \
220 DIAG_ON(sign-compare)
221 #endif
222 #endif
224 /* Disable Lemon warnings. */
225 #if defined(_MSC_VER)
226 #define DIAG_OFF_LEMON()
227 #define DIAG_ON_LEMON()
228 #else
229 #define DIAG_OFF_LEMON() \
230 DIAG_OFF_CLANG(unreachable-code)
231 #define DIAG_ON_LEMON() \
232 DIAG_ON_CLANG(unreachable-code)
233 #endif
236 * Suppress warnings about casting away constness.
237 * Do this only if you know that the pointer is to something that can
238 * be written and, in this context, should be writable.
240 #if defined(__GNUC__) || defined(__clang__)
242 * GCC or a compiler that claims to be GCC-compatible.
243 * We throw in Clang just in case clang-cl doesn't define
244 * __GNUC__; if it does, __GNUC__ should suffice.
246 #define DIAG_OFF_CAST_AWAY_CONST DIAG_OFF(cast-qual)
247 #define DIAG_ON_CAST_AWAY_CONST DIAG_OFF(cast-qual)
248 #elif defined(_MSC_VER)
249 #define DIAG_OFF_CAST_AWAY_CONST
250 #define DIAG_ON_CAST_AWAY_CONST
251 #else
252 #define DIAG_OFF_CAST_AWAY_CONST
253 #define DIAG_ON_CAST_AWAY_CONST
254 #endif
257 * This warning is only supported by GCC since version 7.1 (and not
258 * Clang or other compilers that claim GNU C support).
260 #if WS_GCC_VERSION >= 70100
261 #define DIAG_OFF_STRINGOP_OVERFLOW() DIAG_OFF(stringop-overflow=)
262 #define DIAG_ON_STRINGOP_OVERFLOW() DIAG_ON(stringop-overflow=)
263 #else
264 #define DIAG_OFF_STRINGOP_OVERFLOW()
265 #define DIAG_ON_STRINGOP_OVERFLOW()
266 #endif
269 * For dealing with APIs which are only deprecated in macOS (like the
270 * OpenSSL and MIT/Heimdal Kerberos APIs).
272 * Dear Apple: this is a cross-platform program, and we're not
273 * going to use your Shiny New Frameworks on macOS unless there's
274 * a sufficiently clear benefit to make it worth our while to have
275 * both macOS and non-macOS versions of the code.
277 #ifdef __APPLE__
278 # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
279 # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
280 #else
281 # define USES_APPLE_DEPRECATED_API
282 # define USES_APPLE_RST
283 #endif
285 #ifdef __cplusplus
287 #endif
288 #endif /* __WS_DIAG_CONTROL_H__ */