]>
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)
141 #define DIAG_OFF_DOCUMENTATION \
142 PCAP_DO_PRAGMA(clang diagnostic push) \
143 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation")
144 #define DIAG_ON_DOCUMENTATION \
145 PCAP_DO_PRAGMA(clang diagnostic pop)
146 #elif defined(_MSC_VER)
148 * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
149 * and __pragma(warning(push/pop)).
151 * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
154 #define DIAG_OFF_FLEX \
155 __pragma(warning(push)) \
156 __pragma(warning(disable:4127)) \
157 __pragma(warning(disable:4242)) \
158 __pragma(warning(disable:4244)) \
159 __pragma(warning(disable:4702))
160 #define DIAG_ON_FLEX \
161 __pragma(warning(pop))
164 * Suppress narrowing warnings.
166 #define DIAG_OFF_NARROWING \
167 __pragma(warning(push)) \
168 __pragma(warning(disable:4242)) \
169 __pragma(warning(disable:4311))
170 #define DIAG_ON_NARROWING \
171 __pragma(warning(pop))
174 * Suppress deprecation warnings.
176 #define DIAG_OFF_DEPRECATION \
177 __pragma(warning(push)) \
178 __pragma(warning(disable:4996))
179 #define DIAG_ON_DEPRECATION \
180 __pragma(warning(pop))
181 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
183 * This is GCC 4.6 or later, or a compiler claiming to be that.
184 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
185 * and "GCC diagnostic push/pop" (introduced in 4.6).
187 #define DIAG_OFF_FLEX \
188 PCAP_DO_PRAGMA(GCC diagnostic push) \
189 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
190 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
191 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
192 #define DIAG_ON_FLEX \
193 PCAP_DO_PRAGMA(GCC diagnostic pop)
196 * GCC currently doesn't issue any narrowing warnings.
200 * Suppress deprecation warnings.
202 #define DIAG_OFF_DEPRECATION \
203 PCAP_DO_PRAGMA(GCC diagnostic push) \
204 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
205 #define DIAG_ON_DEPRECATION \
206 PCAP_DO_PRAGMA(GCC diagnostic pop)
209 * Suppress format-truncation= warnings.
210 * GCC 7.1 had introduced this warning option. Earlier versions (at least
211 * one particular copy of GCC 4.6.4) treat the request as a warning.
213 #if PCAP_IS_AT_LEAST_GNUC_VERSION(7,1)
214 #define DIAG_OFF_FORMAT_TRUNCATION \
215 PCAP_DO_PRAGMA(GCC diagnostic push) \
216 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wformat-truncation=")
217 #define DIAG_ON_FORMAT_TRUNCATION \
218 PCAP_DO_PRAGMA(GCC diagnostic pop)
220 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
222 * Sun C compiler version 5.5 (Studio version 8) and later supports "#pragma
225 #define DIAG_OFF_FLEX \
226 PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
227 #define DIAG_ON_FLEX \
228 PCAP_DO_PRAGMA(error_messages(default,E_STATEMENT_NOT_REACHED))
235 * It generates a global declaration of yylval, or the appropriately
236 * prefixed version of yylval, in grammar.h, *even though it's been
237 * told to generate a pure parser, meaning it doesn't have any global
238 * variables*. Bison doesn't do this.
240 * That causes a warning due to the local declaration in the parser
241 * shadowing the global declaration.
243 * So, if the compiler warns about that, we turn off -Wshadow warnings.
245 * In addition, the generated code may have functions with unreachable
246 * code, so suppress warnings about those.
248 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
250 * This is Clang 2.8 or later (including clang-cl, so test this
251 * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
253 #define DIAG_OFF_BISON_BYACC \
254 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
255 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
256 #elif defined(_MSC_VER)
258 * This is Microsoft Visual Studio; we can use
259 * __pragma(warning(disable:XXXX)).
261 #define DIAG_OFF_BISON_BYACC \
262 __pragma(warning(disable:4702))
263 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
265 * This is GCC 4.6 or later, or a compiler claiming to be that.
266 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
267 * but it may not actually work very well prior to 4.6).
269 #define DIAG_OFF_BISON_BYACC \
270 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
271 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
277 * The generated code may have functions with unreachable code and
278 * switches with only a default case, so suppress warnings about those.
280 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
282 * This is Clang 2.8 or later (including clang-cl, so test this
283 * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
285 #define DIAG_OFF_BISON_BYACC \
286 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
287 #elif defined(_MSC_VER)
289 * This is Microsoft Visual Studio; we can use
290 * __pragma(warning(disable:XXXX)).
292 * Suppress some /Wall warnings.
294 #define DIAG_OFF_BISON_BYACC \
295 __pragma(warning(disable:4065)) \
296 __pragma(warning(disable:4127)) \
297 __pragma(warning(disable:4242)) \
298 __pragma(warning(disable:4244)) \
299 __pragma(warning(disable:4702))
300 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
302 * This is GCC 4.6 or later, or a compiler claiming to be that.
303 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
304 * but it may not actually work very well prior to 4.6).
306 #define DIAG_OFF_BISON_BYACC \
307 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
308 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
310 * Same as for DIAG_OFF_FLEX above.
312 #define DIAG_OFF_BISON_BYACC \
313 PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
317 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
319 * Clang appears to let you ignore a result without a warning by
320 * casting the function result to void, so we don't appear to
321 * need this for Clang.
323 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,5)
325 * GCC warns about unused return values if a function is marked as
326 * "warn about ignoring this function's return value".
328 #define DIAG_OFF_WARN_UNUSED_RESULT \
329 PCAP_DO_PRAGMA(GCC diagnostic push) \
330 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-result")
331 #define DIAG_ON_WARN_UNUSED_RESULT \
332 PCAP_DO_PRAGMA(GCC diagnostic pop)
335 * GCC does not currently generate any -Wstrict-prototypes warnings that
336 * would need silencing as is done for Clang above.
341 * GCC needs this on AIX for longjmp().
343 #if PCAP_IS_AT_LEAST_GNUC_VERSION(5,1)
345 * Beware that the effect of this builtin is more than just squelching the
346 * warning! GCC trusts it enough for the process to segfault if the control
347 * flow reaches the builtin (an infinite empty loop in the same context would
348 * squelch the warning and ruin the process too, albeit in a different way).
349 * So please remember to use this very carefully.
351 #define PCAP_UNREACHABLE __builtin_unreachable();
354 #ifndef DIAG_OFF_ENUM_SWITCH
355 #define DIAG_OFF_ENUM_SWITCH
357 #ifndef DIAG_ON_ENUM_SWITCH
358 #define DIAG_ON_ENUM_SWITCH
360 #ifndef DIAG_OFF_DEFAULT_ONLY_SWITCH
361 #define DIAG_OFF_DEFAULT_ONLY_SWITCH
363 #ifndef DIAG_ON_DEFAULT_ONLY_SWITCH
364 #define DIAG_ON_DEFAULT_ONLY_SWITCH
366 #ifndef DIAG_OFF_FLEX
367 #define DIAG_OFF_FLEX
372 #ifndef DIAG_OFF_NARROWING
373 #define DIAG_OFF_NARROWING
375 #ifndef DIAG_ON_NARROWING
376 #define DIAG_ON_NARROWING
378 #ifndef DIAG_OFF_DEPRECATION
379 #define DIAG_OFF_DEPRECATION
381 #ifndef DIAG_ON_DEPRECATION
382 #define DIAG_ON_DEPRECATION
384 #ifndef DIAG_OFF_FORMAT_TRUNCATION
385 #define DIAG_OFF_FORMAT_TRUNCATION
387 #ifndef DIAG_ON_FORMAT_TRUNCATION
388 #define DIAG_ON_FORMAT_TRUNCATION
390 #ifndef DIAG_OFF_BISON_BYACC
391 #define DIAG_OFF_BISON_BYACC
394 // DIAG_ON_BISON_BYACC does not need to be defined.
396 #ifndef DIAG_OFF_WARN_UNUSED_RESULT
397 #define DIAG_OFF_WARN_UNUSED_RESULT
399 #ifndef DIAG_ON_WARN_UNUSED_RESULT
400 #define DIAG_ON_WARN_UNUSED_RESULT
402 #ifndef DIAG_OFF_STRICT_PROTOTYPES
403 #define DIAG_OFF_STRICT_PROTOTYPES
405 #ifndef DIAG_ON_STRICT_PROTOTYPES
406 #define DIAG_ON_STRICT_PROTOTYPES
408 #ifndef DIAG_OFF_DOCUMENTATION
409 #define DIAG_OFF_DOCUMENTATION
411 #ifndef DIAG_ON_DOCUMENTATION
412 #define DIAG_ON_DOCUMENTATION
414 #ifndef PCAP_UNREACHABLE
415 #define PCAP_UNREACHABLE
418 #endif /* _diag_control_h */