]>
The Tcpdump Group git mirrors - libpcap/blob - diag-control.h
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
3 * Copyright (c) 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the Computer Systems
17 * Engineering Group at Lawrence Berkeley Laboratory.
18 * 4. Neither the name of the University nor of the Laboratory may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef _diag_control_h
36 #define _diag_control_h
38 #include "pcap/compiler-tests.h"
40 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) || \
41 PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) || \
42 PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
44 * All these compilers support this way of putting pragmas into #defines.
45 * We use it only if we have a compiler that supports it; see below
46 * for the code that uses it and the #defines that control whether
49 #define PCAP_DO_PRAGMA(x) _Pragma (#x)
53 * Suppress "enum value not explicitly handled in switch" warnings.
54 * We may have to build on multiple different Windows SDKs, so we
55 * may not be able to include all enum values in a switch, as they
56 * won't necessarily be defined on all the SDKs, and, unlike
57 * #defines, there's no easy way to test whether a given enum has
58 * a given value. It *could* be done by the configure script or
62 #define DIAG_OFF_ENUM_SWITCH \
63 __pragma(warning(push)) \
64 __pragma(warning(disable:4061))
65 #define DIAG_ON_ENUM_SWITCH \
66 __pragma(warning(pop))
70 * Suppress "switch statement has only a default case" warnings.
71 * There's a switch in bpf_filter.c that only has additional
75 #define DIAG_OFF_DEFAULT_ONLY_SWITCH \
76 __pragma(warning(push)) \
77 __pragma(warning(disable:4065))
78 #define DIAG_ON_DEFAULT_ONLY_SWITCH \
79 __pragma(warning(pop))
83 * Suppress Flex, narrowing, and deprecation warnings.
85 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
87 * This is Clang 2.8 or later; we can use "clang diagnostic
88 * ignored -Wxxx" and "clang diagnostic push/pop".
90 * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
91 * at least according to the GCC 7.3 documentation. Apparently, Flex
92 * generates code that upsets at least some versions of Clang's
95 * (This could be clang-cl, which defines _MSC_VER, so test this
96 * before testing _MSC_VER.)
98 #define DIAG_OFF_FLEX \
99 PCAP_DO_PRAGMA(clang diagnostic push) \
100 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
101 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
102 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
103 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
104 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
105 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
106 #define DIAG_ON_FLEX \
107 PCAP_DO_PRAGMA(clang diagnostic pop)
110 * Suppress the only narrowing warnings you get from Clang.
112 #define DIAG_OFF_NARROWING \
113 PCAP_DO_PRAGMA(clang diagnostic push) \
114 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
116 #define DIAG_ON_NARROWING \
117 PCAP_DO_PRAGMA(clang diagnostic pop)
120 * Suppress deprecation warnings.
122 #define DIAG_OFF_DEPRECATION \
123 PCAP_DO_PRAGMA(clang diagnostic push) \
124 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
125 #define DIAG_ON_DEPRECATION \
126 PCAP_DO_PRAGMA(clang diagnostic pop)
129 * When Clang correctly detects an old-style function prototype after
130 * preprocessing, the warning can be irrelevant to this source tree because
131 * the prototype comes from a system header macro.
133 #if PCAP_IS_AT_LEAST_CLANG_VERSION(5,0)
134 #define DIAG_OFF_STRICT_PROTOTYPES \
135 PCAP_DO_PRAGMA(clang diagnostic push) \
136 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wstrict-prototypes")
137 #define DIAG_ON_STRICT_PROTOTYPES \
138 PCAP_DO_PRAGMA(clang diagnostic pop)
140 #elif defined(_MSC_VER)
142 * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
143 * and __pragma(warning(push/pop)).
145 * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
148 #define DIAG_OFF_FLEX \
149 __pragma(warning(push)) \
150 __pragma(warning(disable:4127)) \
151 __pragma(warning(disable:4242)) \
152 __pragma(warning(disable:4244)) \
153 __pragma(warning(disable:4702))
154 #define DIAG_ON_FLEX \
155 __pragma(warning(pop))
158 * Suppress narrowing warnings.
160 #define DIAG_OFF_NARROWING \
161 __pragma(warning(push)) \
162 __pragma(warning(disable:4242)) \
163 __pragma(warning(disable:4311))
164 #define DIAG_ON_NARROWING \
165 __pragma(warning(pop))
168 * Suppress deprecation warnings.
170 #define DIAG_OFF_DEPRECATION \
171 __pragma(warning(push)) \
172 __pragma(warning(disable:4996))
173 #define DIAG_ON_DEPRECATION \
174 __pragma(warning(pop))
175 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
177 * This is GCC 4.6 or later, or a compiler claiming to be that.
178 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
179 * and "GCC diagnostic push/pop" (introduced in 4.6).
181 #define DIAG_OFF_FLEX \
182 PCAP_DO_PRAGMA(GCC diagnostic push) \
183 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
184 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
185 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
186 #define DIAG_ON_FLEX \
187 PCAP_DO_PRAGMA(GCC diagnostic pop)
190 * GCC currently doesn't issue any narrowing warnings.
194 * Suppress deprecation warnings.
196 #define DIAG_OFF_DEPRECATION \
197 PCAP_DO_PRAGMA(GCC diagnostic push) \
198 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
199 #define DIAG_ON_DEPRECATION \
200 PCAP_DO_PRAGMA(GCC diagnostic pop)
203 * Suppress format-truncation= warnings.
204 * GCC 7.1 had introduced this warning option. Earlier versions (at least
205 * one particular copy of GCC 4.6.4) treat the request as a warning.
207 #if PCAP_IS_AT_LEAST_GNUC_VERSION(7,1)
208 #define DIAG_OFF_FORMAT_TRUNCATION \
209 PCAP_DO_PRAGMA(GCC diagnostic push) \
210 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wformat-truncation=")
211 #define DIAG_ON_FORMAT_TRUNCATION \
212 PCAP_DO_PRAGMA(GCC diagnostic pop)
214 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
216 * Sun C compiler version 5.5 (Studio version 8) and later supports "#pragma
219 #define DIAG_OFF_FLEX \
220 PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
221 #define DIAG_ON_FLEX \
222 PCAP_DO_PRAGMA(error_messages(default,E_STATEMENT_NOT_REACHED))
229 * It generates a global declaration of yylval, or the appropriately
230 * prefixed version of yylval, in grammar.h, *even though it's been
231 * told to generate a pure parser, meaning it doesn't have any global
232 * variables*. Bison doesn't do this.
234 * That causes a warning due to the local declaration in the parser
235 * shadowing the global declaration.
237 * So, if the compiler warns about that, we turn off -Wshadow warnings.
239 * In addition, the generated code may have functions with unreachable
240 * code, so suppress warnings about those.
242 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
244 * This is Clang 2.8 or later (including clang-cl, so test this
245 * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
247 #define DIAG_OFF_BISON_BYACC \
248 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
249 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
250 #elif defined(_MSC_VER)
252 * This is Microsoft Visual Studio; we can use
253 * __pragma(warning(disable:XXXX)).
255 #define DIAG_OFF_BISON_BYACC \
256 __pragma(warning(disable:4702))
257 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
259 * This is GCC 4.6 or later, or a compiler claiming to be that.
260 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
261 * but it may not actually work very well prior to 4.6).
263 #define DIAG_OFF_BISON_BYACC \
264 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
265 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
271 * The generated code may have functions with unreachable code and
272 * switches with only a default case, so suppress warnings about those.
274 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
276 * This is Clang 2.8 or later (including clang-cl, so test this
277 * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
279 #define DIAG_OFF_BISON_BYACC \
280 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
281 #elif defined(_MSC_VER)
283 * This is Microsoft Visual Studio; we can use
284 * __pragma(warning(disable:XXXX)).
286 * Suppress some /Wall warnings.
288 #define DIAG_OFF_BISON_BYACC \
289 __pragma(warning(disable:4065)) \
290 __pragma(warning(disable:4127)) \
291 __pragma(warning(disable:4242)) \
292 __pragma(warning(disable:4244)) \
293 __pragma(warning(disable:4702))
294 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
296 * This is GCC 4.6 or later, or a compiler claiming to be that.
297 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
298 * but it may not actually work very well prior to 4.6).
300 #define DIAG_OFF_BISON_BYACC \
301 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
302 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
304 * Same as for DIAG_OFF_FLEX above.
306 #define DIAG_OFF_BISON_BYACC \
307 PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
311 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
313 * Clang appears to let you ignore a result without a warning by
314 * casting the function result to void, so we don't appear to
315 * need this for Clang.
317 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,5)
319 * GCC warns about unused return values if a function is marked as
320 * "warn about ignoring this function's return value".
322 #define DIAG_OFF_WARN_UNUSED_RESULT \
323 PCAP_DO_PRAGMA(GCC diagnostic push) \
324 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-result")
325 #define DIAG_ON_WARN_UNUSED_RESULT \
326 PCAP_DO_PRAGMA(GCC diagnostic pop)
329 * GCC does not currently generate any -Wstrict-prototypes warnings that
330 * would need silencing as is done for Clang above.
335 * GCC needs this on AIX for longjmp().
337 #if PCAP_IS_AT_LEAST_GNUC_VERSION(5,1)
339 * Beware that the effect of this builtin is more than just squelching the
340 * warning! GCC trusts it enough for the process to segfault if the control
341 * flow reaches the builtin (an infinite empty loop in the same context would
342 * squelch the warning and ruin the process too, albeit in a different way).
343 * So please remember to use this very carefully.
345 #define PCAP_UNREACHABLE __builtin_unreachable();
348 #ifndef DIAG_OFF_ENUM_SWITCH
349 #define DIAG_OFF_ENUM_SWITCH
351 #ifndef DIAG_ON_ENUM_SWITCH
352 #define DIAG_ON_ENUM_SWITCH
354 #ifndef DIAG_OFF_DEFAULT_ONLY_SWITCH
355 #define DIAG_OFF_DEFAULT_ONLY_SWITCH
357 #ifndef DIAG_ON_DEFAULT_ONLY_SWITCH
358 #define DIAG_ON_DEFAULT_ONLY_SWITCH
360 #ifndef DIAG_OFF_FLEX
361 #define DIAG_OFF_FLEX
366 #ifndef DIAG_OFF_NARROWING
367 #define DIAG_OFF_NARROWING
369 #ifndef DIAG_ON_NARROWING
370 #define DIAG_ON_NARROWING
372 #ifndef DIAG_OFF_DEPRECATION
373 #define DIAG_OFF_DEPRECATION
375 #ifndef DIAG_ON_DEPRECATION
376 #define DIAG_ON_DEPRECATION
378 #ifndef DIAG_OFF_FORMAT_TRUNCATION
379 #define DIAG_OFF_FORMAT_TRUNCATION
381 #ifndef DIAG_ON_FORMAT_TRUNCATION
382 #define DIAG_ON_FORMAT_TRUNCATION
384 #ifndef DIAG_OFF_BISON_BYACC
385 #define DIAG_OFF_BISON_BYACC
388 // DIAG_ON_BISON_BYACC does not need to be defined.
390 #ifndef DIAG_OFF_WARN_UNUSED_RESULT
391 #define DIAG_OFF_WARN_UNUSED_RESULT
393 #ifndef DIAG_ON_WARN_UNUSED_RESULT
394 #define DIAG_ON_WARN_UNUSED_RESULT
396 #ifndef DIAG_OFF_STRICT_PROTOTYPES
397 #define DIAG_OFF_STRICT_PROTOTYPES
399 #ifndef DIAG_ON_STRICT_PROTOTYPES
400 #define DIAG_ON_STRICT_PROTOTYPES
402 #ifndef PCAP_UNREACHABLE
403 #define PCAP_UNREACHABLE
406 #endif /* _diag_control_h */