]> The Tcpdump Group git mirrors - libpcap/blob - diag-control.h
Add -Wformat-nonliteral and fix most warnings that come up
[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 * Suppress signed-vs-unsigned comparison and narrowing warnings.
56 */
57 #define DIAG_OFF_FLEX \
58 __pragma(warning(push)) \
59 __pragma(warning(disable:4127)) \
60 __pragma(warning(disable:4242)) \
61 __pragma(warning(disable:4244))
62 #define DIAG_ON_FLEX __pragma(warning(pop))
63 #else
64 /*
65 * Suppress -Wsigned-compare warnings.
66 *
67 * Suppress -Wdocumentation warnings with Clang; GCC doesn't
68 * support -Wdocumentation, at least according to the GCC 7.3
69 * documentation. Apparently, Flex generates code that upsets
70 * at least some versions of Clang's -Wdocumentation.
71 */
72 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
73 /*
74 * This is Clang 2.8 or later; we can use "clang diagnostic
75 * ignored -Wxxx" and "clang diagnostic push/pop".
76 */
77 #define DIAG_OFF_FLEX \
78 PCAP_DO_PRAGMA(clang diagnostic push) \
79 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
80 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
81 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
82 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter")
83 #define DIAG_ON_FLEX \
84 PCAP_DO_PRAGMA(clang diagnostic pop)
85 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
86 /*
87 * This is GCC 4.6 or later, or a compiler claiming to be that.
88 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
89 * and "GCC diagnostic push/pop" (introduced in 4.6).
90 */
91 #define DIAG_OFF_FLEX \
92 PCAP_DO_PRAGMA(GCC diagnostic push) \
93 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
94 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter")
95 #define DIAG_ON_FLEX \
96 PCAP_DO_PRAGMA(GCC diagnostic pop)
97 #else
98 /*
99 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
100 * claiming to be that; there's nothing we know of that we can do.
101 */
102 #define DIAG_OFF_FLEX
103 #define DIAG_ON_FLEX
104 #endif
105 #endif
106
107 #ifdef YYBYACC
108 /*
109 * Berkeley YACC.
110 *
111 * It generates a global declaration of yylval, or the appropriately
112 * prefixed version of yylval, in grammar.h, *even though it's been
113 * told to generate a pure parser, meaning it doesn't have any global
114 * variables*. Bison doesn't do this.
115 *
116 * That causes a warning due to the local declaration in the parser
117 * shadowing the global declaration.
118 *
119 * So, if we have _Pragma, and have pragmas to suppress diagnostics,
120 * we use it to turn off -Wshadow warnings.
121 */
122 #if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
123 /*
124 * This is Clang 2.8 or later; we can use "clang diagnostic
125 * ignored -Wxxx" and "clang diagnostic push/pop".
126 */
127 #define DIAG_OFF_BISON_BYACC \
128 PCAP_DO_PRAGMA(clang diagnostic push) \
129 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow")
130 #define DIAG_ON_BISON_BYACC \
131 PCAP_DO_PRAGMA(clang diagnostic pop)
132 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
133 /*
134 * This is GCC 4.6 or later, or a compiler claiming to be that.
135 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
136 * and "GCC diagnostic push/pop" (introduced in 4.6).
137 */
138 #define DIAG_OFF_BISON_BYACC \
139 PCAP_DO_PRAGMA(GCC diagnostic push) \
140 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow")
141 #define DIAG_ON_BISON_BYACC \
142 PCAP_DO_PRAGMA(GCC diagnostic pop)
143 #else
144 /*
145 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
146 * claiming to be that; there's nothing we know of that we can do.
147 */
148 #define DIAG_OFF_BISON_BYACC
149 #define DIAG_ON_BISON_BYACC
150 #endif
151 #else
152 /*
153 * Bison.
154 */
155 #if defined(_MSC_VER)
156 /*
157 * Suppress some /Wall warnings.
158 */
159 #define DIAG_OFF_BISON_BYACC \
160 __pragma(warning(push)) \
161 __pragma(warning(disable:4127)) \
162 __pragma(warning(disable:4242)) \
163 __pragma(warning(disable:4244)) \
164 __pragma(warning(disable:4702))
165 #define DIAG_ON_BISON_BYACC __pragma(warning(pop))
166 #else
167 /*
168 * Nothing to suppress.
169 */
170 #define DIAG_OFF_BISON_BYACC
171 #define DIAG_ON_BISON_BYACC
172 #endif
173 #endif
174
175 #endif /* _diag_control_h */