]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libpcap/diag-control.h
MFV r333789: libpcap 1.9.0 (pre-release)
[FreeBSD/FreeBSD.git] / contrib / libpcap / diag-control.h
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2 /*
3  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4  *      The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
21  *
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
32  * SUCH DAMAGE.
33  */
34
35 #ifndef _diag_control_h
36 #define _diag_control_h
37
38 #include "pcap/compiler-tests.h"
39
40 #ifndef _MSC_VER
41   /*
42    * Clang and GCC both support this way of putting pragmas into #defines.
43    * We don't use it unless we have a compiler that supports it; the
44    * warning-suppressing pragmas differ between Clang and GCC, so we test
45    * for both of those separately.
46    */
47   #define PCAP_DO_PRAGMA(x) _Pragma (#x)
48 #endif
49
50 /*
51  * Suppress Flex warnings.
52  */
53 #if defined(_MSC_VER)
54   /*
55    * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
56    * and __pragma(warning(push/pop)).
57    *
58    * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
59    * code warnings.
60    */
61   #define DIAG_OFF_FLEX \
62     __pragma(warning(push)) \
63     __pragma(warning(disable:4127)) \
64     __pragma(warning(disable:4242)) \
65     __pragma(warning(disable:4244)) \
66     __pragma(warning(disable:4702))
67   #define DIAG_ON_FLEX  __pragma(warning(pop))
68 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
69   /*
70    * This is Clang 2.8 or later; we can use "clang diagnostic
71    * ignored -Wxxx" and "clang diagnostic push/pop".
72    *
73    * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
74    * at least according to the GCC 7.3 documentation.  Apparently, Flex
75    * generates code that upsets at least some versions of Clang's
76    * -Wdocumentation.
77    */
78   #define DIAG_OFF_FLEX \
79     PCAP_DO_PRAGMA(clang diagnostic push) \
80     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
81     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
82     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
83     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
84     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
85   #define DIAG_ON_FLEX \
86     PCAP_DO_PRAGMA(clang diagnostic pop)
87 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
88   /*
89    * This is GCC 4.6 or later, or a compiler claiming to be that.
90    * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
91    * and "GCC diagnostic push/pop" (introduced in 4.6).
92    */
93   #define DIAG_OFF_FLEX \
94     PCAP_DO_PRAGMA(GCC diagnostic push) \
95     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
96     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
97     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
98   #define DIAG_ON_FLEX \
99     PCAP_DO_PRAGMA(GCC diagnostic pop)
100 #else
101   /*
102    * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
103    * or a compiler claiming to be that; there's nothing we know of that
104    * we can do.
105    */
106   #define DIAG_OFF_FLEX
107   #define DIAG_ON_FLEX
108 #endif
109
110 #ifdef YYBYACC
111   /*
112    * Berkeley YACC.
113    *
114    * It generates a global declaration of yylval, or the appropriately
115    * prefixed version of yylval, in grammar.h, *even though it's been
116    * told to generate a pure parser, meaning it doesn't have any global
117    * variables*.  Bison doesn't do this.
118    *
119    * That causes a warning due to the local declaration in the parser
120    * shadowing the global declaration.
121    *
122    * So, if the compiler warns about that, we turn off -Wshadow warnings.
123    */
124   #if defined(_MSC_VER)
125     /*
126      * This is Microsoft Visual Studio; we can use
127      * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)).
128      *
129      * Suppress unreachable code warnings.
130      */
131     #define DIAG_OFF_BISON_BYACC \
132       __pragma(warning(push)) \
133       __pragma(warning(disable:4702))
134     #define DIAG_ON_BISON_BYACC  __pragma(warning(pop))
135   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
136     /*
137      * This is Clang 2.8 or later; we can use "clang diagnostic
138      * ignored -Wxxx" and "clang diagnostic push/pop".
139      */
140     #define DIAG_OFF_BISON_BYACC \
141       PCAP_DO_PRAGMA(clang diagnostic push) \
142       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
143       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
144     #define DIAG_ON_BISON_BYACC \
145       PCAP_DO_PRAGMA(clang diagnostic pop)
146   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
147     /*
148      * This is GCC 4.6 or later, or a compiler claiming to be that.
149      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
150      * and "GCC diagnostic push/pop" (introduced in 4.6).
151      */
152     #define DIAG_OFF_BISON_BYACC \
153       PCAP_DO_PRAGMA(GCC diagnostic push) \
154       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
155       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
156     #define DIAG_ON_BISON_BYACC \
157       PCAP_DO_PRAGMA(GCC diagnostic pop)
158   #else
159     /*
160      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
161      * claiming to be that; there's nothing we know of that we can do.
162      */
163     #define DIAG_OFF_BISON_BYACC
164     #define DIAG_ON_BISON_BYACC
165   #endif
166 #else
167   /*
168    * Bison.
169    */
170   #if defined(_MSC_VER)
171     /*
172      * This is Microsoft Visual Studio; we can use
173      * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)).
174      *
175      * Suppress some /Wall warnings.
176      */
177     #define DIAG_OFF_BISON_BYACC \
178       __pragma(warning(push)) \
179       __pragma(warning(disable:4127)) \
180       __pragma(warning(disable:4242)) \
181       __pragma(warning(disable:4244)) \
182       __pragma(warning(disable:4702))
183     #define DIAG_ON_BISON_BYACC  __pragma(warning(pop))
184   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
185     /*
186      * This is Clang 2.8 or later; we can use "clang diagnostic
187      * ignored -Wxxx" and "clang diagnostic push/pop".
188      */
189     #define DIAG_OFF_BISON_BYACC \
190       PCAP_DO_PRAGMA(clang diagnostic push) \
191       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
192     #define DIAG_ON_BISON_BYACC \
193       PCAP_DO_PRAGMA(clang diagnostic pop)
194   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
195     /*
196      * This is GCC 4.6 or later, or a compiler claiming to be that.
197      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
198      * and "GCC diagnostic push/pop" (introduced in 4.6).
199      */
200     #define DIAG_OFF_BISON_BYACC \
201       PCAP_DO_PRAGMA(GCC diagnostic push) \
202       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
203     #define DIAG_ON_BISON_BYACC \
204       PCAP_DO_PRAGMA(GCC diagnostic pop)
205   #else
206     /*
207      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
208      * claiming to be that; there's nothing we know of that we can do.
209      */
210     #define DIAG_OFF_BISON_BYACC
211     #define DIAG_ON_BISON_BYACC
212   #endif
213 #endif
214
215 #endif /* _diag_control_h */