xref: /dragonfly/contrib/libpcap/diag-control.h (revision ea16f64e)
13a289941SAaron LI /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
23a289941SAaron LI /*
33a289941SAaron LI  * Copyright (c) 1993, 1994, 1995, 1996, 1997
43a289941SAaron LI  *	The Regents of the University of California.  All rights reserved.
53a289941SAaron LI  *
63a289941SAaron LI  * Redistribution and use in source and binary forms, with or without
73a289941SAaron LI  * modification, are permitted provided that the following conditions
83a289941SAaron LI  * are met:
93a289941SAaron LI  * 1. Redistributions of source code must retain the above copyright
103a289941SAaron LI  *    notice, this list of conditions and the following disclaimer.
113a289941SAaron LI  * 2. Redistributions in binary form must reproduce the above copyright
123a289941SAaron LI  *    notice, this list of conditions and the following disclaimer in the
133a289941SAaron LI  *    documentation and/or other materials provided with the distribution.
143a289941SAaron LI  * 3. All advertising materials mentioning features or use of this software
153a289941SAaron LI  *    must display the following acknowledgement:
163a289941SAaron LI  *	This product includes software developed by the Computer Systems
173a289941SAaron LI  *	Engineering Group at Lawrence Berkeley Laboratory.
183a289941SAaron LI  * 4. Neither the name of the University nor of the Laboratory may be used
193a289941SAaron LI  *    to endorse or promote products derived from this software without
203a289941SAaron LI  *    specific prior written permission.
213a289941SAaron LI  *
223a289941SAaron LI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233a289941SAaron LI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243a289941SAaron LI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253a289941SAaron LI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263a289941SAaron LI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273a289941SAaron LI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283a289941SAaron LI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293a289941SAaron LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303a289941SAaron LI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313a289941SAaron LI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323a289941SAaron LI  * SUCH DAMAGE.
333a289941SAaron LI  */
343a289941SAaron LI 
353a289941SAaron LI #ifndef _diag_control_h
363a289941SAaron LI #define _diag_control_h
373a289941SAaron LI 
383a289941SAaron LI #include "pcap/compiler-tests.h"
393a289941SAaron LI 
403a289941SAaron LI #ifndef _MSC_VER
413a289941SAaron LI   /*
423a289941SAaron LI    * Clang and GCC both support this way of putting pragmas into #defines.
433a289941SAaron LI    * We don't use it unless we have a compiler that supports it; the
443a289941SAaron LI    * warning-suppressing pragmas differ between Clang and GCC, so we test
453a289941SAaron LI    * for both of those separately.
463a289941SAaron LI    */
473a289941SAaron LI   #define PCAP_DO_PRAGMA(x) _Pragma (#x)
483a289941SAaron LI #endif
493a289941SAaron LI 
503a289941SAaron LI /*
51*ea16f64eSAntonio Huete Jimenez  * Suppress "enum value not explicitly handled in switch" warnings.
52*ea16f64eSAntonio Huete Jimenez  * We may have to build on multiple different Windows SDKs, so we
53*ea16f64eSAntonio Huete Jimenez  * may not be able to include all enum values in a switch, as they
54*ea16f64eSAntonio Huete Jimenez  * won't necessarily be defined on all the SDKs, and, unlike
55*ea16f64eSAntonio Huete Jimenez  * #defines, there's no easy way to test whether a given enum has
56*ea16f64eSAntonio Huete Jimenez  * a given value.  It *could* be done by the configure script or
57*ea16f64eSAntonio Huete Jimenez  * CMake tests.
58*ea16f64eSAntonio Huete Jimenez  */
59*ea16f64eSAntonio Huete Jimenez #if defined(_MSC_VER)
60*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_ENUM_SWITCH \
61*ea16f64eSAntonio Huete Jimenez     __pragma(warning(push)) \
62*ea16f64eSAntonio Huete Jimenez     __pragma(warning(disable:4061))
63*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_ENUM_SWITCH \
64*ea16f64eSAntonio Huete Jimenez     __pragma(warning(pop))
65*ea16f64eSAntonio Huete Jimenez #else
66*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_ENUM_SWITCH
67*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_ENUM_SWITCH
68*ea16f64eSAntonio Huete Jimenez #endif
69*ea16f64eSAntonio Huete Jimenez 
70*ea16f64eSAntonio Huete Jimenez /*
71*ea16f64eSAntonio Huete Jimenez  * Suppress "switch statement has only a default case" warnings.
72*ea16f64eSAntonio Huete Jimenez  * There's a switch in bpf_filter.c that only has additional
73*ea16f64eSAntonio Huete Jimenez  * cases on Linux.
74*ea16f64eSAntonio Huete Jimenez  */
75*ea16f64eSAntonio Huete Jimenez #if defined(_MSC_VER)
76*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEFAULT_ONLY_SWITCH \
77*ea16f64eSAntonio Huete Jimenez     __pragma(warning(push)) \
78*ea16f64eSAntonio Huete Jimenez     __pragma(warning(disable:4065))
79*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEFAULT_ONLY_SWITCH \
80*ea16f64eSAntonio Huete Jimenez     __pragma(warning(pop))
81*ea16f64eSAntonio Huete Jimenez #else
82*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEFAULT_ONLY_SWITCH
83*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEFAULT_ONLY_SWITCH
84*ea16f64eSAntonio Huete Jimenez #endif
85*ea16f64eSAntonio Huete Jimenez 
86*ea16f64eSAntonio Huete Jimenez /*
87*ea16f64eSAntonio Huete Jimenez  * Suppress Flex, narrowing, and deprecation warnings.
883a289941SAaron LI  */
893a289941SAaron LI #if defined(_MSC_VER)
903a289941SAaron LI   /*
913a289941SAaron LI    * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
923a289941SAaron LI    * and __pragma(warning(push/pop)).
933a289941SAaron LI    *
943a289941SAaron LI    * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
953a289941SAaron LI    * code warnings.
963a289941SAaron LI    */
973a289941SAaron LI   #define DIAG_OFF_FLEX \
983a289941SAaron LI     __pragma(warning(push)) \
993a289941SAaron LI     __pragma(warning(disable:4127)) \
1003a289941SAaron LI     __pragma(warning(disable:4242)) \
1013a289941SAaron LI     __pragma(warning(disable:4244)) \
1023a289941SAaron LI     __pragma(warning(disable:4702))
103*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_FLEX \
104*ea16f64eSAntonio Huete Jimenez     __pragma(warning(pop))
105*ea16f64eSAntonio Huete Jimenez 
106*ea16f64eSAntonio Huete Jimenez   /*
107*ea16f64eSAntonio Huete Jimenez    * Suppress narrowing warnings.
108*ea16f64eSAntonio Huete Jimenez    */
109*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_NARROWING \
110*ea16f64eSAntonio Huete Jimenez     __pragma(warning(push)) \
111*ea16f64eSAntonio Huete Jimenez     __pragma(warning(disable:4242)) \
112*ea16f64eSAntonio Huete Jimenez     __pragma(warning(disable:4311))
113*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_NARROWING \
114*ea16f64eSAntonio Huete Jimenez     __pragma(warning(pop))
115*ea16f64eSAntonio Huete Jimenez 
116*ea16f64eSAntonio Huete Jimenez   /*
117*ea16f64eSAntonio Huete Jimenez    * Suppress deprecation warnings.
118*ea16f64eSAntonio Huete Jimenez    */
119*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEPRECATION \
120*ea16f64eSAntonio Huete Jimenez     __pragma(warning(push)) \
121*ea16f64eSAntonio Huete Jimenez     __pragma(warning(disable:4996))
122*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEPRECATION \
123*ea16f64eSAntonio Huete Jimenez     __pragma(warning(pop))
1243a289941SAaron LI #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
1253a289941SAaron LI   /*
1263a289941SAaron LI    * This is Clang 2.8 or later; we can use "clang diagnostic
1273a289941SAaron LI    * ignored -Wxxx" and "clang diagnostic push/pop".
1283a289941SAaron LI    *
1293a289941SAaron LI    * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
1303a289941SAaron LI    * at least according to the GCC 7.3 documentation.  Apparently, Flex
1313a289941SAaron LI    * generates code that upsets at least some versions of Clang's
1323a289941SAaron LI    * -Wdocumentation.
1333a289941SAaron LI    */
1343a289941SAaron LI   #define DIAG_OFF_FLEX \
1353a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic push) \
1363a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
1373a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
138*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
1393a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
1403a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
1413a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
1423a289941SAaron LI   #define DIAG_ON_FLEX \
1433a289941SAaron LI     PCAP_DO_PRAGMA(clang diagnostic pop)
144*ea16f64eSAntonio Huete Jimenez 
145*ea16f64eSAntonio Huete Jimenez   /*
146*ea16f64eSAntonio Huete Jimenez    * Suppress the only narrowing warnings you get from Clang.
147*ea16f64eSAntonio Huete Jimenez    */
148*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_NARROWING \
149*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic push) \
150*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
151*ea16f64eSAntonio Huete Jimenez 
152*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_NARROWING \
153*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic pop)
154*ea16f64eSAntonio Huete Jimenez 
155*ea16f64eSAntonio Huete Jimenez   /*
156*ea16f64eSAntonio Huete Jimenez    * Suppress deprecation warnings.
157*ea16f64eSAntonio Huete Jimenez    */
158*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEPRECATION \
159*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic push) \
160*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
161*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEPRECATION \
162*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(clang diagnostic pop)
1633a289941SAaron LI #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
1643a289941SAaron LI   /*
1653a289941SAaron LI    * This is GCC 4.6 or later, or a compiler claiming to be that.
1663a289941SAaron LI    * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
1673a289941SAaron LI    * and "GCC diagnostic push/pop" (introduced in 4.6).
1683a289941SAaron LI    */
1693a289941SAaron LI   #define DIAG_OFF_FLEX \
1703a289941SAaron LI     PCAP_DO_PRAGMA(GCC diagnostic push) \
1713a289941SAaron LI     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
1723a289941SAaron LI     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
1733a289941SAaron LI     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
1743a289941SAaron LI   #define DIAG_ON_FLEX \
1753a289941SAaron LI     PCAP_DO_PRAGMA(GCC diagnostic pop)
176*ea16f64eSAntonio Huete Jimenez 
177*ea16f64eSAntonio Huete Jimenez   /*
178*ea16f64eSAntonio Huete Jimenez    * GCC currently doesn't issue any narrowing warnings.
179*ea16f64eSAntonio Huete Jimenez    */
180*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_NARROWING
181*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_NARROWING
182*ea16f64eSAntonio Huete Jimenez 
183*ea16f64eSAntonio Huete Jimenez   /*
184*ea16f64eSAntonio Huete Jimenez    * Suppress deprecation warnings.
185*ea16f64eSAntonio Huete Jimenez    */
186*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEPRECATION \
187*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(GCC diagnostic push) \
188*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
189*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEPRECATION \
190*ea16f64eSAntonio Huete Jimenez     PCAP_DO_PRAGMA(GCC diagnostic pop)
1913a289941SAaron LI #else
1923a289941SAaron LI   /*
1933a289941SAaron LI    * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
1943a289941SAaron LI    * or a compiler claiming to be that; there's nothing we know of that
1953a289941SAaron LI    * we can do.
1963a289941SAaron LI    */
1973a289941SAaron LI   #define DIAG_OFF_FLEX
1983a289941SAaron LI   #define DIAG_ON_FLEX
199*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_NARROWING
200*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_NARROWING
201*ea16f64eSAntonio Huete Jimenez   #define DIAG_OFF_DEPRECATION
202*ea16f64eSAntonio Huete Jimenez   #define DIAG_ON_DEPRECATION
2033a289941SAaron LI #endif
2043a289941SAaron LI 
2053a289941SAaron LI #ifdef YYBYACC
2063a289941SAaron LI   /*
2073a289941SAaron LI    * Berkeley YACC.
2083a289941SAaron LI    *
2093a289941SAaron LI    * It generates a global declaration of yylval, or the appropriately
2103a289941SAaron LI    * prefixed version of yylval, in grammar.h, *even though it's been
2113a289941SAaron LI    * told to generate a pure parser, meaning it doesn't have any global
2123a289941SAaron LI    * variables*.  Bison doesn't do this.
2133a289941SAaron LI    *
2143a289941SAaron LI    * That causes a warning due to the local declaration in the parser
2153a289941SAaron LI    * shadowing the global declaration.
2163a289941SAaron LI    *
2173a289941SAaron LI    * So, if the compiler warns about that, we turn off -Wshadow warnings.
2183a289941SAaron LI    *
2193a289941SAaron LI    * In addition, the generated code may have functions with unreachable
2203a289941SAaron LI    * code, so suppress warnings about those.
2213a289941SAaron LI    */
2223a289941SAaron LI   #if defined(_MSC_VER)
2233a289941SAaron LI     /*
2243a289941SAaron LI      * This is Microsoft Visual Studio; we can use
225*ea16f64eSAntonio Huete Jimenez      * __pragma(warning(disable:XXXX)).
2263a289941SAaron LI      */
2273a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
2283a289941SAaron LI       __pragma(warning(disable:4702))
2293a289941SAaron LI   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
2303a289941SAaron LI     /*
2313a289941SAaron LI      * This is Clang 2.8 or later; we can use "clang diagnostic
232*ea16f64eSAntonio Huete Jimenez      * ignored -Wxxx".
2333a289941SAaron LI      */
2343a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
2353a289941SAaron LI       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
2363a289941SAaron LI       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
2373a289941SAaron LI   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
2383a289941SAaron LI     /*
2393a289941SAaron LI      * This is GCC 4.6 or later, or a compiler claiming to be that.
240*ea16f64eSAntonio Huete Jimenez      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
241*ea16f64eSAntonio Huete Jimenez      * but it may not actually work very well prior to 4.6).
2423a289941SAaron LI      */
2433a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
2443a289941SAaron LI       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
2453a289941SAaron LI       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
2463a289941SAaron LI   #else
2473a289941SAaron LI     /*
2483a289941SAaron LI      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
2493a289941SAaron LI      * claiming to be that; there's nothing we know of that we can do.
2503a289941SAaron LI      */
2513a289941SAaron LI     #define DIAG_OFF_BISON_BYACC
2523a289941SAaron LI   #endif
2533a289941SAaron LI #else
2543a289941SAaron LI   /*
2553a289941SAaron LI    * Bison.
2563a289941SAaron LI    *
257*ea16f64eSAntonio Huete Jimenez    * The generated code may have functions with unreachable code and
258*ea16f64eSAntonio Huete Jimenez    * switches with only a default case, so suppress warnings about those.
2593a289941SAaron LI    */
2603a289941SAaron LI   #if defined(_MSC_VER)
2613a289941SAaron LI     /*
2623a289941SAaron LI      * This is Microsoft Visual Studio; we can use
263*ea16f64eSAntonio Huete Jimenez      * __pragma(warning(disable:XXXX)).
2643a289941SAaron LI      *
2653a289941SAaron LI      * Suppress some /Wall warnings.
2663a289941SAaron LI      */
2673a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
268*ea16f64eSAntonio Huete Jimenez       __pragma(warning(disable:4065)) \
2693a289941SAaron LI       __pragma(warning(disable:4127)) \
2703a289941SAaron LI       __pragma(warning(disable:4242)) \
2713a289941SAaron LI       __pragma(warning(disable:4244)) \
2723a289941SAaron LI       __pragma(warning(disable:4702))
2733a289941SAaron LI   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
2743a289941SAaron LI     /*
2753a289941SAaron LI      * This is Clang 2.8 or later; we can use "clang diagnostic
276*ea16f64eSAntonio Huete Jimenez      * ignored -Wxxx".
2773a289941SAaron LI      */
2783a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
2793a289941SAaron LI       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
2803a289941SAaron LI   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
2813a289941SAaron LI     /*
2823a289941SAaron LI      * This is GCC 4.6 or later, or a compiler claiming to be that.
283*ea16f64eSAntonio Huete Jimenez      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
284*ea16f64eSAntonio Huete Jimenez      * but it may not actually work very well prior to 4.6).
2853a289941SAaron LI      */
2863a289941SAaron LI     #define DIAG_OFF_BISON_BYACC \
2873a289941SAaron LI       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
2883a289941SAaron LI   #else
2893a289941SAaron LI     /*
2903a289941SAaron LI      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
2913a289941SAaron LI      * claiming to be that; there's nothing we know of that we can do.
2923a289941SAaron LI      */
2933a289941SAaron LI     #define DIAG_OFF_BISON_BYACC
2943a289941SAaron LI   #endif
2953a289941SAaron LI #endif
2963a289941SAaron LI 
2973a289941SAaron LI #endif /* _diag_control_h */
298