xref: /freebsd/contrib/libpcap/diag-control.h (revision afdbf109c6a661a729938f68211054a0a50d38ac)
1b00ab754SHans Petter Selasky /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2b00ab754SHans Petter Selasky /*
3b00ab754SHans Petter Selasky  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4b00ab754SHans Petter Selasky  *	The Regents of the University of California.  All rights reserved.
5b00ab754SHans Petter Selasky  *
6b00ab754SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
7b00ab754SHans Petter Selasky  * modification, are permitted provided that the following conditions
8b00ab754SHans Petter Selasky  * are met:
9b00ab754SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
10b00ab754SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
11b00ab754SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
12b00ab754SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
13b00ab754SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
14b00ab754SHans Petter Selasky  * 3. All advertising materials mentioning features or use of this software
15b00ab754SHans Petter Selasky  *    must display the following acknowledgement:
16b00ab754SHans Petter Selasky  *	This product includes software developed by the Computer Systems
17b00ab754SHans Petter Selasky  *	Engineering Group at Lawrence Berkeley Laboratory.
18b00ab754SHans Petter Selasky  * 4. Neither the name of the University nor of the Laboratory may be used
19b00ab754SHans Petter Selasky  *    to endorse or promote products derived from this software without
20b00ab754SHans Petter Selasky  *    specific prior written permission.
21b00ab754SHans Petter Selasky  *
22b00ab754SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23b00ab754SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24b00ab754SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25b00ab754SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26b00ab754SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27b00ab754SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28b00ab754SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29b00ab754SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30b00ab754SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31b00ab754SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32b00ab754SHans Petter Selasky  * SUCH DAMAGE.
33b00ab754SHans Petter Selasky  */
34b00ab754SHans Petter Selasky 
35b00ab754SHans Petter Selasky #ifndef _diag_control_h
36b00ab754SHans Petter Selasky #define _diag_control_h
37b00ab754SHans Petter Selasky 
38b00ab754SHans Petter Selasky #include "pcap/compiler-tests.h"
39b00ab754SHans Petter Selasky 
40*afdbf109SJoseph Mingrone #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) || \
41*afdbf109SJoseph Mingrone     PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) || \
42*afdbf109SJoseph Mingrone     PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
43b00ab754SHans Petter Selasky   /*
44*afdbf109SJoseph Mingrone    * All these compilers support this way of putting pragmas into #defines.
456f9cba8fSJoseph Mingrone    * We use it only if we have a compiler that supports it; see below
466f9cba8fSJoseph Mingrone    * for the code that uses it and the #defines that control whether
476f9cba8fSJoseph Mingrone    * that code is used.
48b00ab754SHans Petter Selasky    */
49b00ab754SHans Petter Selasky   #define PCAP_DO_PRAGMA(x) _Pragma (#x)
50b00ab754SHans Petter Selasky #endif
51b00ab754SHans Petter Selasky 
52b00ab754SHans Petter Selasky /*
536f9cba8fSJoseph Mingrone  * Suppress "enum value not explicitly handled in switch" warnings.
546f9cba8fSJoseph Mingrone  * We may have to build on multiple different Windows SDKs, so we
556f9cba8fSJoseph Mingrone  * may not be able to include all enum values in a switch, as they
566f9cba8fSJoseph Mingrone  * won't necessarily be defined on all the SDKs, and, unlike
576f9cba8fSJoseph Mingrone  * #defines, there's no easy way to test whether a given enum has
586f9cba8fSJoseph Mingrone  * a given value.  It *could* be done by the configure script or
596f9cba8fSJoseph Mingrone  * CMake tests.
60b00ab754SHans Petter Selasky  */
61b00ab754SHans Petter Selasky #if defined(_MSC_VER)
626f9cba8fSJoseph Mingrone   #define DIAG_OFF_ENUM_SWITCH \
636f9cba8fSJoseph Mingrone     __pragma(warning(push)) \
646f9cba8fSJoseph Mingrone     __pragma(warning(disable:4061))
656f9cba8fSJoseph Mingrone   #define DIAG_ON_ENUM_SWITCH \
666f9cba8fSJoseph Mingrone     __pragma(warning(pop))
676f9cba8fSJoseph Mingrone #endif
686f9cba8fSJoseph Mingrone 
696f9cba8fSJoseph Mingrone /*
706f9cba8fSJoseph Mingrone  * Suppress "switch statement has only a default case" warnings.
716f9cba8fSJoseph Mingrone  * There's a switch in bpf_filter.c that only has additional
726f9cba8fSJoseph Mingrone  * cases on Linux.
736f9cba8fSJoseph Mingrone  */
746f9cba8fSJoseph Mingrone #if defined(_MSC_VER)
756f9cba8fSJoseph Mingrone   #define DIAG_OFF_DEFAULT_ONLY_SWITCH \
766f9cba8fSJoseph Mingrone     __pragma(warning(push)) \
776f9cba8fSJoseph Mingrone     __pragma(warning(disable:4065))
786f9cba8fSJoseph Mingrone   #define DIAG_ON_DEFAULT_ONLY_SWITCH \
796f9cba8fSJoseph Mingrone     __pragma(warning(pop))
806f9cba8fSJoseph Mingrone #endif
816f9cba8fSJoseph Mingrone 
826f9cba8fSJoseph Mingrone /*
836f9cba8fSJoseph Mingrone  * Suppress Flex, narrowing, and deprecation warnings.
846f9cba8fSJoseph Mingrone  */
856f9cba8fSJoseph Mingrone #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
866f9cba8fSJoseph Mingrone   /*
876f9cba8fSJoseph Mingrone    * This is Clang 2.8 or later; we can use "clang diagnostic
886f9cba8fSJoseph Mingrone    * ignored -Wxxx" and "clang diagnostic push/pop".
896f9cba8fSJoseph Mingrone    *
906f9cba8fSJoseph Mingrone    * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
916f9cba8fSJoseph Mingrone    * at least according to the GCC 7.3 documentation.  Apparently, Flex
926f9cba8fSJoseph Mingrone    * generates code that upsets at least some versions of Clang's
936f9cba8fSJoseph Mingrone    * -Wdocumentation.
946f9cba8fSJoseph Mingrone    *
956f9cba8fSJoseph Mingrone    * (This could be clang-cl, which defines _MSC_VER, so test this
966f9cba8fSJoseph Mingrone    * before testing _MSC_VER.)
976f9cba8fSJoseph Mingrone    */
986f9cba8fSJoseph Mingrone   #define DIAG_OFF_FLEX \
996f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic push) \
1006f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
1016f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
1026f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
1036f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
1046f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
1056f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
1066f9cba8fSJoseph Mingrone   #define DIAG_ON_FLEX \
1076f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic pop)
1086f9cba8fSJoseph Mingrone 
1096f9cba8fSJoseph Mingrone   /*
1106f9cba8fSJoseph Mingrone    * Suppress the only narrowing warnings you get from Clang.
1116f9cba8fSJoseph Mingrone    */
1126f9cba8fSJoseph Mingrone   #define DIAG_OFF_NARROWING \
1136f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic push) \
1146f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
1156f9cba8fSJoseph Mingrone 
1166f9cba8fSJoseph Mingrone   #define DIAG_ON_NARROWING \
1176f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic pop)
1186f9cba8fSJoseph Mingrone 
1196f9cba8fSJoseph Mingrone   /*
1206f9cba8fSJoseph Mingrone    * Suppress deprecation warnings.
1216f9cba8fSJoseph Mingrone    */
1226f9cba8fSJoseph Mingrone   #define DIAG_OFF_DEPRECATION \
1236f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic push) \
1246f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
1256f9cba8fSJoseph Mingrone   #define DIAG_ON_DEPRECATION \
1266f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic pop)
127*afdbf109SJoseph Mingrone 
128*afdbf109SJoseph Mingrone   /*
129*afdbf109SJoseph Mingrone    * When Clang correctly detects an old-style function prototype after
130*afdbf109SJoseph Mingrone    * preprocessing, the warning can be irrelevant to this source tree because
131*afdbf109SJoseph Mingrone    * the prototype comes from a system header macro.
132*afdbf109SJoseph Mingrone    */
133*afdbf109SJoseph Mingrone   #if PCAP_IS_AT_LEAST_CLANG_VERSION(5,0)
134*afdbf109SJoseph Mingrone     #define DIAG_OFF_STRICT_PROTOTYPES \
135*afdbf109SJoseph Mingrone       PCAP_DO_PRAGMA(clang diagnostic push) \
136*afdbf109SJoseph Mingrone       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wstrict-prototypes")
137*afdbf109SJoseph Mingrone     #define DIAG_ON_STRICT_PROTOTYPES \
138*afdbf109SJoseph Mingrone       PCAP_DO_PRAGMA(clang diagnostic pop)
139*afdbf109SJoseph Mingrone   #endif
140*afdbf109SJoseph Mingrone 
141*afdbf109SJoseph Mingrone   #define DIAG_OFF_DOCUMENTATION \
142*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic push) \
143*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation")
144*afdbf109SJoseph Mingrone   #define DIAG_ON_DOCUMENTATION \
145*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic pop)
146*afdbf109SJoseph Mingrone 
147*afdbf109SJoseph Mingrone   #define DIAG_OFF_SIGN_COMPARE \
148*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic push) \
149*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare")
150*afdbf109SJoseph Mingrone   #define DIAG_ON_SIGN_COMPARE \
151*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(clang diagnostic pop)
1526f9cba8fSJoseph Mingrone #elif defined(_MSC_VER)
153b00ab754SHans Petter Selasky   /*
154b00ab754SHans Petter Selasky    * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
155b00ab754SHans Petter Selasky    * and __pragma(warning(push/pop)).
156b00ab754SHans Petter Selasky    *
157b00ab754SHans Petter Selasky    * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
158b00ab754SHans Petter Selasky    * code warnings.
159b00ab754SHans Petter Selasky    */
160b00ab754SHans Petter Selasky   #define DIAG_OFF_FLEX \
161b00ab754SHans Petter Selasky     __pragma(warning(push)) \
162b00ab754SHans Petter Selasky     __pragma(warning(disable:4127)) \
163b00ab754SHans Petter Selasky     __pragma(warning(disable:4242)) \
164b00ab754SHans Petter Selasky     __pragma(warning(disable:4244)) \
165b00ab754SHans Petter Selasky     __pragma(warning(disable:4702))
166b00ab754SHans Petter Selasky   #define DIAG_ON_FLEX \
1676f9cba8fSJoseph Mingrone     __pragma(warning(pop))
1686f9cba8fSJoseph Mingrone 
1696f9cba8fSJoseph Mingrone   /*
1706f9cba8fSJoseph Mingrone    * Suppress narrowing warnings.
1716f9cba8fSJoseph Mingrone    */
1726f9cba8fSJoseph Mingrone   #define DIAG_OFF_NARROWING \
1736f9cba8fSJoseph Mingrone     __pragma(warning(push)) \
1746f9cba8fSJoseph Mingrone     __pragma(warning(disable:4242)) \
1756f9cba8fSJoseph Mingrone     __pragma(warning(disable:4311))
1766f9cba8fSJoseph Mingrone   #define DIAG_ON_NARROWING \
1776f9cba8fSJoseph Mingrone     __pragma(warning(pop))
1786f9cba8fSJoseph Mingrone 
1796f9cba8fSJoseph Mingrone   /*
1806f9cba8fSJoseph Mingrone    * Suppress deprecation warnings.
1816f9cba8fSJoseph Mingrone    */
1826f9cba8fSJoseph Mingrone   #define DIAG_OFF_DEPRECATION \
1836f9cba8fSJoseph Mingrone     __pragma(warning(push)) \
1846f9cba8fSJoseph Mingrone     __pragma(warning(disable:4996))
1856f9cba8fSJoseph Mingrone   #define DIAG_ON_DEPRECATION \
1866f9cba8fSJoseph Mingrone     __pragma(warning(pop))
187b00ab754SHans Petter Selasky #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
188b00ab754SHans Petter Selasky   /*
189b00ab754SHans Petter Selasky    * This is GCC 4.6 or later, or a compiler claiming to be that.
190b00ab754SHans Petter Selasky    * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
191b00ab754SHans Petter Selasky    * and "GCC diagnostic push/pop" (introduced in 4.6).
192b00ab754SHans Petter Selasky    */
193b00ab754SHans Petter Selasky   #define DIAG_OFF_FLEX \
194b00ab754SHans Petter Selasky     PCAP_DO_PRAGMA(GCC diagnostic push) \
195b00ab754SHans Petter Selasky     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
196b00ab754SHans Petter Selasky     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
197b00ab754SHans Petter Selasky     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
198b00ab754SHans Petter Selasky   #define DIAG_ON_FLEX \
199b00ab754SHans Petter Selasky     PCAP_DO_PRAGMA(GCC diagnostic pop)
2006f9cba8fSJoseph Mingrone 
2016f9cba8fSJoseph Mingrone   /*
2026f9cba8fSJoseph Mingrone    * GCC currently doesn't issue any narrowing warnings.
2036f9cba8fSJoseph Mingrone    */
2046f9cba8fSJoseph Mingrone 
2056f9cba8fSJoseph Mingrone   /*
2066f9cba8fSJoseph Mingrone    * Suppress deprecation warnings.
2076f9cba8fSJoseph Mingrone    */
2086f9cba8fSJoseph Mingrone   #define DIAG_OFF_DEPRECATION \
2096f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic push) \
2106f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
2116f9cba8fSJoseph Mingrone   #define DIAG_ON_DEPRECATION \
2126f9cba8fSJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic pop)
2136f9cba8fSJoseph Mingrone 
2146f9cba8fSJoseph Mingrone   /*
2156f9cba8fSJoseph Mingrone    * Suppress format-truncation= warnings.
2166f9cba8fSJoseph Mingrone    * GCC 7.1 had introduced this warning option. Earlier versions (at least
2176f9cba8fSJoseph Mingrone    * one particular copy of GCC 4.6.4) treat the request as a warning.
2186f9cba8fSJoseph Mingrone    */
2196f9cba8fSJoseph Mingrone   #if PCAP_IS_AT_LEAST_GNUC_VERSION(7,1)
2206f9cba8fSJoseph Mingrone     #define DIAG_OFF_FORMAT_TRUNCATION \
2216f9cba8fSJoseph Mingrone       PCAP_DO_PRAGMA(GCC diagnostic push) \
2226f9cba8fSJoseph Mingrone       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wformat-truncation=")
2236f9cba8fSJoseph Mingrone     #define DIAG_ON_FORMAT_TRUNCATION \
2246f9cba8fSJoseph Mingrone       PCAP_DO_PRAGMA(GCC diagnostic pop)
2256f9cba8fSJoseph Mingrone   #endif
226*afdbf109SJoseph Mingrone #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
227b00ab754SHans Petter Selasky   /*
228*afdbf109SJoseph Mingrone    * Sun C compiler version 5.5 (Studio version 8) and later supports "#pragma
229*afdbf109SJoseph Mingrone    * error_messages()".
230b00ab754SHans Petter Selasky    */
231*afdbf109SJoseph Mingrone   #define DIAG_OFF_FLEX \
232*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
233*afdbf109SJoseph Mingrone   #define DIAG_ON_FLEX \
234*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(error_messages(default,E_STATEMENT_NOT_REACHED))
235b00ab754SHans Petter Selasky #endif
236b00ab754SHans Petter Selasky 
237b00ab754SHans Petter Selasky #ifdef YYBYACC
238b00ab754SHans Petter Selasky   /*
239b00ab754SHans Petter Selasky    * Berkeley YACC.
240b00ab754SHans Petter Selasky    *
241b00ab754SHans Petter Selasky    * It generates a global declaration of yylval, or the appropriately
242b00ab754SHans Petter Selasky    * prefixed version of yylval, in grammar.h, *even though it's been
243b00ab754SHans Petter Selasky    * told to generate a pure parser, meaning it doesn't have any global
244b00ab754SHans Petter Selasky    * variables*.  Bison doesn't do this.
245b00ab754SHans Petter Selasky    *
246b00ab754SHans Petter Selasky    * That causes a warning due to the local declaration in the parser
247b00ab754SHans Petter Selasky    * shadowing the global declaration.
248b00ab754SHans Petter Selasky    *
249b00ab754SHans Petter Selasky    * So, if the compiler warns about that, we turn off -Wshadow warnings.
25057e22627SCy Schubert    *
25157e22627SCy Schubert    * In addition, the generated code may have functions with unreachable
25257e22627SCy Schubert    * code, so suppress warnings about those.
253b00ab754SHans Petter Selasky    */
2546f9cba8fSJoseph Mingrone   #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
255b00ab754SHans Petter Selasky     /*
2566f9cba8fSJoseph Mingrone      * This is Clang 2.8 or later (including clang-cl, so test this
2576f9cba8fSJoseph Mingrone      * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
258b00ab754SHans Petter Selasky      */
259b00ab754SHans Petter Selasky     #define DIAG_OFF_BISON_BYACC \
260b00ab754SHans Petter Selasky       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
261b00ab754SHans Petter Selasky       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
2626f9cba8fSJoseph Mingrone   #elif defined(_MSC_VER)
2636f9cba8fSJoseph Mingrone     /*
2646f9cba8fSJoseph Mingrone      * This is Microsoft Visual Studio; we can use
2656f9cba8fSJoseph Mingrone      * __pragma(warning(disable:XXXX)).
2666f9cba8fSJoseph Mingrone      */
2676f9cba8fSJoseph Mingrone     #define DIAG_OFF_BISON_BYACC \
2686f9cba8fSJoseph Mingrone       __pragma(warning(disable:4702))
269b00ab754SHans Petter Selasky   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
270b00ab754SHans Petter Selasky     /*
271b00ab754SHans Petter Selasky      * This is GCC 4.6 or later, or a compiler claiming to be that.
2726f9cba8fSJoseph Mingrone      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
2736f9cba8fSJoseph Mingrone      * but it may not actually work very well prior to 4.6).
274b00ab754SHans Petter Selasky      */
275b00ab754SHans Petter Selasky     #define DIAG_OFF_BISON_BYACC \
276b00ab754SHans Petter Selasky       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
277b00ab754SHans Petter Selasky       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
278b00ab754SHans Petter Selasky   #endif
279b00ab754SHans Petter Selasky #else
280b00ab754SHans Petter Selasky   /*
281b00ab754SHans Petter Selasky    * Bison.
28257e22627SCy Schubert    *
2836f9cba8fSJoseph Mingrone    * The generated code may have functions with unreachable code and
2846f9cba8fSJoseph Mingrone    * switches with only a default case, so suppress warnings about those.
285b00ab754SHans Petter Selasky    */
2866f9cba8fSJoseph Mingrone   #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
2876f9cba8fSJoseph Mingrone     /*
2886f9cba8fSJoseph Mingrone      * This is Clang 2.8 or later (including clang-cl, so test this
2896f9cba8fSJoseph Mingrone      * before _MSC_VER); we can use "clang diagnostic ignored -Wxxx".
2906f9cba8fSJoseph Mingrone      */
2916f9cba8fSJoseph Mingrone     #define DIAG_OFF_BISON_BYACC \
2926f9cba8fSJoseph Mingrone       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
2936f9cba8fSJoseph Mingrone   #elif defined(_MSC_VER)
294b00ab754SHans Petter Selasky     /*
295b00ab754SHans Petter Selasky      * This is Microsoft Visual Studio; we can use
2966f9cba8fSJoseph Mingrone      * __pragma(warning(disable:XXXX)).
297b00ab754SHans Petter Selasky      *
298b00ab754SHans Petter Selasky      * Suppress some /Wall warnings.
299b00ab754SHans Petter Selasky      */
300b00ab754SHans Petter Selasky     #define DIAG_OFF_BISON_BYACC \
3016f9cba8fSJoseph Mingrone       __pragma(warning(disable:4065)) \
302b00ab754SHans Petter Selasky       __pragma(warning(disable:4127)) \
303b00ab754SHans Petter Selasky       __pragma(warning(disable:4242)) \
304b00ab754SHans Petter Selasky       __pragma(warning(disable:4244)) \
305b00ab754SHans Petter Selasky       __pragma(warning(disable:4702))
306b00ab754SHans Petter Selasky   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
307b00ab754SHans Petter Selasky     /*
308b00ab754SHans Petter Selasky      * This is GCC 4.6 or later, or a compiler claiming to be that.
3096f9cba8fSJoseph Mingrone      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
3106f9cba8fSJoseph Mingrone      * but it may not actually work very well prior to 4.6).
311b00ab754SHans Petter Selasky      */
312b00ab754SHans Petter Selasky     #define DIAG_OFF_BISON_BYACC \
313b00ab754SHans Petter Selasky       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
314*afdbf109SJoseph Mingrone   #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
315b00ab754SHans Petter Selasky     /*
316*afdbf109SJoseph Mingrone      * Same as for DIAG_OFF_FLEX above.
317b00ab754SHans Petter Selasky      */
318*afdbf109SJoseph Mingrone     #define DIAG_OFF_BISON_BYACC \
319*afdbf109SJoseph Mingrone       PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
320b00ab754SHans Petter Selasky   #endif
321b00ab754SHans Petter Selasky #endif
322b00ab754SHans Petter Selasky 
323*afdbf109SJoseph Mingrone #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
324*afdbf109SJoseph Mingrone   /*
325*afdbf109SJoseph Mingrone    * Clang appears to let you ignore a result without a warning by
326*afdbf109SJoseph Mingrone    * casting the function result to void, so we don't appear to
327*afdbf109SJoseph Mingrone    * need this for Clang.
328*afdbf109SJoseph Mingrone    */
329*afdbf109SJoseph Mingrone #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,5)
330*afdbf109SJoseph Mingrone   /*
331*afdbf109SJoseph Mingrone    * GCC warns about unused return values if a function is marked as
332*afdbf109SJoseph Mingrone    * "warn about ignoring this function's return value".
333*afdbf109SJoseph Mingrone    */
334*afdbf109SJoseph Mingrone   #define DIAG_OFF_WARN_UNUSED_RESULT \
335*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic push) \
336*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-result")
337*afdbf109SJoseph Mingrone   #define DIAG_ON_WARN_UNUSED_RESULT \
338*afdbf109SJoseph Mingrone     PCAP_DO_PRAGMA(GCC diagnostic pop)
339*afdbf109SJoseph Mingrone 
340*afdbf109SJoseph Mingrone   /*
341*afdbf109SJoseph Mingrone    * GCC does not currently generate any -Wstrict-prototypes warnings that
342*afdbf109SJoseph Mingrone    * would need silencing as is done for Clang above.
343*afdbf109SJoseph Mingrone    */
344*afdbf109SJoseph Mingrone #endif
345*afdbf109SJoseph Mingrone 
3466f9cba8fSJoseph Mingrone /*
3476f9cba8fSJoseph Mingrone  * GCC needs this on AIX for longjmp().
3486f9cba8fSJoseph Mingrone  */
3496f9cba8fSJoseph Mingrone #if PCAP_IS_AT_LEAST_GNUC_VERSION(5,1)
3506f9cba8fSJoseph Mingrone   /*
3516f9cba8fSJoseph Mingrone    * Beware that the effect of this builtin is more than just squelching the
3526f9cba8fSJoseph Mingrone    * warning! GCC trusts it enough for the process to segfault if the control
3536f9cba8fSJoseph Mingrone    * flow reaches the builtin (an infinite empty loop in the same context would
3546f9cba8fSJoseph Mingrone    * squelch the warning and ruin the process too, albeit in a different way).
3556f9cba8fSJoseph Mingrone    * So please remember to use this very carefully.
3566f9cba8fSJoseph Mingrone    */
3576f9cba8fSJoseph Mingrone   #define PCAP_UNREACHABLE __builtin_unreachable();
358*afdbf109SJoseph Mingrone #endif
359*afdbf109SJoseph Mingrone 
360*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_ENUM_SWITCH
361*afdbf109SJoseph Mingrone #define DIAG_OFF_ENUM_SWITCH
362*afdbf109SJoseph Mingrone #endif
363*afdbf109SJoseph Mingrone #ifndef DIAG_ON_ENUM_SWITCH
364*afdbf109SJoseph Mingrone #define DIAG_ON_ENUM_SWITCH
365*afdbf109SJoseph Mingrone #endif
366*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_DEFAULT_ONLY_SWITCH
367*afdbf109SJoseph Mingrone #define DIAG_OFF_DEFAULT_ONLY_SWITCH
368*afdbf109SJoseph Mingrone #endif
369*afdbf109SJoseph Mingrone #ifndef DIAG_ON_DEFAULT_ONLY_SWITCH
370*afdbf109SJoseph Mingrone #define DIAG_ON_DEFAULT_ONLY_SWITCH
371*afdbf109SJoseph Mingrone #endif
372*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_FLEX
373*afdbf109SJoseph Mingrone #define DIAG_OFF_FLEX
374*afdbf109SJoseph Mingrone #endif
375*afdbf109SJoseph Mingrone #ifndef DIAG_ON_FLEX
376*afdbf109SJoseph Mingrone #define DIAG_ON_FLEX
377*afdbf109SJoseph Mingrone #endif
378*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_NARROWING
379*afdbf109SJoseph Mingrone #define DIAG_OFF_NARROWING
380*afdbf109SJoseph Mingrone #endif
381*afdbf109SJoseph Mingrone #ifndef DIAG_ON_NARROWING
382*afdbf109SJoseph Mingrone #define DIAG_ON_NARROWING
383*afdbf109SJoseph Mingrone #endif
384*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_DEPRECATION
385*afdbf109SJoseph Mingrone #define DIAG_OFF_DEPRECATION
386*afdbf109SJoseph Mingrone #endif
387*afdbf109SJoseph Mingrone #ifndef DIAG_ON_DEPRECATION
388*afdbf109SJoseph Mingrone #define DIAG_ON_DEPRECATION
389*afdbf109SJoseph Mingrone #endif
390*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_FORMAT_TRUNCATION
391*afdbf109SJoseph Mingrone #define DIAG_OFF_FORMAT_TRUNCATION
392*afdbf109SJoseph Mingrone #endif
393*afdbf109SJoseph Mingrone #ifndef DIAG_ON_FORMAT_TRUNCATION
394*afdbf109SJoseph Mingrone #define DIAG_ON_FORMAT_TRUNCATION
395*afdbf109SJoseph Mingrone #endif
396*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_BISON_BYACC
397*afdbf109SJoseph Mingrone #define DIAG_OFF_BISON_BYACC
398*afdbf109SJoseph Mingrone #endif
399*afdbf109SJoseph Mingrone //
400*afdbf109SJoseph Mingrone // DIAG_ON_BISON_BYACC does not need to be defined.
401*afdbf109SJoseph Mingrone //
402*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_WARN_UNUSED_RESULT
403*afdbf109SJoseph Mingrone #define DIAG_OFF_WARN_UNUSED_RESULT
404*afdbf109SJoseph Mingrone #endif
405*afdbf109SJoseph Mingrone #ifndef DIAG_ON_WARN_UNUSED_RESULT
406*afdbf109SJoseph Mingrone #define DIAG_ON_WARN_UNUSED_RESULT
407*afdbf109SJoseph Mingrone #endif
408*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_STRICT_PROTOTYPES
409*afdbf109SJoseph Mingrone #define DIAG_OFF_STRICT_PROTOTYPES
410*afdbf109SJoseph Mingrone #endif
411*afdbf109SJoseph Mingrone #ifndef DIAG_ON_STRICT_PROTOTYPES
412*afdbf109SJoseph Mingrone #define DIAG_ON_STRICT_PROTOTYPES
413*afdbf109SJoseph Mingrone #endif
414*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_DOCUMENTATION
415*afdbf109SJoseph Mingrone #define DIAG_OFF_DOCUMENTATION
416*afdbf109SJoseph Mingrone #endif
417*afdbf109SJoseph Mingrone #ifndef DIAG_ON_DOCUMENTATION
418*afdbf109SJoseph Mingrone #define DIAG_ON_DOCUMENTATION
419*afdbf109SJoseph Mingrone #endif
420*afdbf109SJoseph Mingrone #ifndef DIAG_OFF_SIGN_COMPARE
421*afdbf109SJoseph Mingrone #define DIAG_OFF_SIGN_COMPARE
422*afdbf109SJoseph Mingrone #endif
423*afdbf109SJoseph Mingrone #ifndef DIAG_ON_SIGN_COMPARE
424*afdbf109SJoseph Mingrone #define DIAG_ON_SIGN_COMPARE
425*afdbf109SJoseph Mingrone #endif
426*afdbf109SJoseph Mingrone #ifndef PCAP_UNREACHABLE
4276f9cba8fSJoseph Mingrone #define PCAP_UNREACHABLE
4286f9cba8fSJoseph Mingrone #endif
4296f9cba8fSJoseph Mingrone 
430b00ab754SHans Petter Selasky #endif /* _diag_control_h */
431