]> The Tcpdump Group git mirrors - libpcap/blob - diag-control.h
Suppress warnings about the deprecation of gethostbyname().
[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 \
68 __pragma(warning(pop))
69
70 /*
71 * Suppress narrowing warnings.
72 */
73 #define DIAG_OFF_NARROWING \
74 __pragma(warning(push)) \
75 __pragma(warning(disable:4242))
76 #define DIAG_ON_NARROWING \
77 __pragma(warning(pop))
78
79 /*
80 * Suppress deprecation warnings.
81 */
82 #define DIAG_OFF_DEPRECATION \
83 __pragma(warning(push)) \
84 __pragma(warning(disable:4996))
85 #define DIAG_ON_DEPRECATION \
86 __pragma(warning(pop))
87 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
88 /*
89 * This is Clang 2.8 or later; we can use "clang diagnostic
90 * ignored -Wxxx" and "clang diagnostic push/pop".
91 *
92 * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
93 * at least according to the GCC 7.3 documentation. Apparently, Flex
94 * generates code that upsets at least some versions of Clang's
95 * -Wdocumentation.
96 */
97 #define DIAG_OFF_FLEX \
98 PCAP_DO_PRAGMA(clang diagnostic push) \
99 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
100 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
101 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
102 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
103 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
104 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
105 #define DIAG_ON_FLEX \
106 PCAP_DO_PRAGMA(clang diagnostic pop)
107
108 /*
109 * Suppress the only narrowing warnings you get from Clang.
110 */
111 #define DIAG_OFF_NARROWING \
112 PCAP_DO_PRAGMA(clang diagnostic push) \
113 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
114
115 #define DIAG_ON_NARROWING \
116 PCAP_DO_PRAGMA(clang diagnostic pop)
117
118 /*
119 * Suppress deprecation warnings.
120 */
121 #define DIAG_OFF_DEPRECATION \
122 PCAP_DO_PRAGMA(clang diagnostic push) \
123 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
124 #define DIAG_ON_DEPRECATION \
125 PCAP_DO_PRAGMA(clang diagnostic pop)
126 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
127 /*
128 * This is GCC 4.6 or later, or a compiler claiming to be that.
129 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
130 * and "GCC diagnostic push/pop" (introduced in 4.6).
131 */
132 #define DIAG_OFF_FLEX \
133 PCAP_DO_PRAGMA(GCC diagnostic push) \
134 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
135 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
136 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
137 #define DIAG_ON_FLEX \
138 PCAP_DO_PRAGMA(GCC diagnostic pop)
139
140 /*
141 * GCC currently doesn't issue any narrowing warnings.
142 */
143 #define DIAG_OFF_NARROWING
144 #define DIAG_ON_NARROWING
145
146 /*
147 * Suppress deprecation warnings.
148 */
149 #define DIAG_OFF_DEPRECATION \
150 PCAP_DO_PRAGMA(GCC diagnostic push) \
151 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
152 #define DIAG_ON_DEPRECATION \
153 PCAP_DO_PRAGMA(GCC diagnostic pop)
154 #else
155 /*
156 * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
157 * or a compiler claiming to be that; there's nothing we know of that
158 * we can do.
159 */
160 #define DIAG_OFF_FLEX
161 #define DIAG_ON_FLEX
162 #define DIAG_OFF_NARROWING
163 #define DIAG_ON_NARROWING
164 #define DIAG_OFF_DEPRECATION
165 #define DIAG_ON_DEPRECATION
166 #endif
167
168 #ifdef YYBYACC
169 /*
170 * Berkeley YACC.
171 *
172 * It generates a global declaration of yylval, or the appropriately
173 * prefixed version of yylval, in grammar.h, *even though it's been
174 * told to generate a pure parser, meaning it doesn't have any global
175 * variables*. Bison doesn't do this.
176 *
177 * That causes a warning due to the local declaration in the parser
178 * shadowing the global declaration.
179 *
180 * So, if the compiler warns about that, we turn off -Wshadow warnings.
181 *
182 * In addition, the generated code may have functions with unreachable
183 * code, so suppress warnings about those.
184 */
185 #if defined(_MSC_VER)
186 /*
187 * This is Microsoft Visual Studio; we can use
188 * __pragma(warning(disable:XXXX)).
189 */
190 #define DIAG_OFF_BISON_BYACC \
191 __pragma(warning(disable:4702))
192 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
193 /*
194 * This is Clang 2.8 or later; we can use "clang diagnostic
195 * ignored -Wxxx".
196 */
197 #define DIAG_OFF_BISON_BYACC \
198 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
199 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
200 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
201 /*
202 * This is GCC 4.6 or later, or a compiler claiming to be that.
203 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
204 * but it may not actually work very well prior to 4.6).
205 */
206 #define DIAG_OFF_BISON_BYACC \
207 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
208 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
209 #else
210 /*
211 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
212 * claiming to be that; there's nothing we know of that we can do.
213 */
214 #define DIAG_OFF_BISON_BYACC
215 #endif
216 #else
217 /*
218 * Bison.
219 *
220 * The generated code may have functions with unreachable code, so
221 * suppress warnings about those.
222 */
223 #if defined(_MSC_VER)
224 /*
225 * This is Microsoft Visual Studio; we can use
226 * __pragma(warning(disable:XXXX)).
227 *
228 * Suppress some /Wall warnings.
229 */
230 #define DIAG_OFF_BISON_BYACC \
231 __pragma(warning(disable:4127)) \
232 __pragma(warning(disable:4242)) \
233 __pragma(warning(disable:4244)) \
234 __pragma(warning(disable:4702))
235 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
236 /*
237 * This is Clang 2.8 or later; we can use "clang diagnostic
238 * ignored -Wxxx".
239 */
240 #define DIAG_OFF_BISON_BYACC \
241 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
242 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
243 /*
244 * This is GCC 4.6 or later, or a compiler claiming to be that.
245 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
246 * but it may not actually work very well prior to 4.6).
247 */
248 #define DIAG_OFF_BISON_BYACC \
249 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
250 #else
251 /*
252 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
253 * claiming to be that; there's nothing we know of that we can do.
254 */
255 #define DIAG_OFF_BISON_BYACC
256 #endif
257 #endif
258
259 #endif /* _diag_control_h */