This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enable Perl compile-time warnings at all places
[perl5.git] / warnings.h
1 /* -*- buffer-read-only: t -*-
2    !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
3    This file is built by regen/warnings.pl.
4    Any changes made here will be lost!
5  */
6
7
8 #define Off(x)                  ((x) / 8)
9 #define Bit(x)                  (1 << ((x) % 8))
10 #define IsSet(a, x)             ((a)[Off(x)] & Bit(x))
11
12
13 #define G_WARN_OFF              0       /* $^W == 0 */
14 #define G_WARN_ON               1       /* -w flag and $^W != 0 */
15 #define G_WARN_ALL_ON           2       /* -W flag */
16 #define G_WARN_ALL_OFF          4       /* -X flag */
17 #define G_WARN_ONCE             8       /* set if 'once' ever enabled */
18 #define G_WARN_ALL_MASK         (G_WARN_ALL_ON|G_WARN_ALL_OFF)
19
20 #define pWARN_STD               NULL
21 #define pWARN_ALL               (STRLEN *) &PL_WARN_ALL    /* use warnings 'all' */
22 #define pWARN_NONE              (STRLEN *) &PL_WARN_NONE   /* no  warnings 'all' */
23
24 #define specialWARN(x)          ((x) == pWARN_STD || (x) == pWARN_ALL ||        \
25                                  (x) == pWARN_NONE)
26
27 /* if PL_warnhook is set to this value, then warnings die */
28 #define PERL_WARNHOOK_FATAL     (&PL_sv_placeholder)
29
30 /* Warnings Categories added in Perl 5.008 */
31
32 #define WARN_ALL                         0
33 #define WARN_CLOSURE                     1
34 #define WARN_DEPRECATED                  2
35 #define WARN_EXITING                     3
36 #define WARN_GLOB                        4
37 #define WARN_IO                          5
38 #define WARN_CLOSED                      6
39 #define WARN_EXEC                        7
40 #define WARN_LAYER                       8
41 #define WARN_NEWLINE                     9
42 #define WARN_PIPE                        10
43 #define WARN_UNOPENED                    11
44 #define WARN_MISC                        12
45 #define WARN_NUMERIC                     13
46 #define WARN_ONCE                        14
47 #define WARN_OVERFLOW                    15
48 #define WARN_PACK                        16
49 #define WARN_PORTABLE                    17
50 #define WARN_RECURSION                   18
51 #define WARN_REDEFINE                    19
52 #define WARN_REGEXP                      20
53 #define WARN_SEVERE                      21
54 #define WARN_DEBUGGING                   22
55 #define WARN_INPLACE                     23
56 #define WARN_INTERNAL                    24
57 #define WARN_MALLOC                      25
58 #define WARN_SIGNAL                      26
59 #define WARN_SUBSTR                      27
60 #define WARN_SYNTAX                      28
61 #define WARN_AMBIGUOUS                   29
62 #define WARN_BAREWORD                    30
63 #define WARN_DIGIT                       31
64 #define WARN_PARENTHESIS                 32
65 #define WARN_PRECEDENCE                  33
66 #define WARN_PRINTF                      34
67 #define WARN_PROTOTYPE                   35
68 #define WARN_QW                          36
69 #define WARN_RESERVED                    37
70 #define WARN_SEMICOLON                   38
71 #define WARN_TAINT                       39
72 #define WARN_THREADS                     40
73 #define WARN_UNINITIALIZED               41
74 #define WARN_UNPACK                      42
75 #define WARN_UNTIE                       43
76 #define WARN_UTF8                        44
77 #define WARN_VOID                        45
78
79 /* Warnings Categories added in Perl 5.011 */
80
81 #define WARN_IMPRECISION                 46
82 #define WARN_ILLEGALPROTO                47
83
84 /* Warnings Categories added in Perl 5.013 */
85
86 #define WARN_NON_UNICODE                 48
87 #define WARN_NONCHAR                     49
88 #define WARN_SURROGATE                   50
89
90 /* Warnings Categories added in Perl 5.017 */
91
92 #define WARN_EXPERIMENTAL                51
93 #define WARN_EXPERIMENTAL__LEXICAL_SUBS  52
94 #define WARN_EXPERIMENTAL__REGEX_SETS    53
95 #define WARN_EXPERIMENTAL__SMARTMATCH    54
96
97 /* Warnings Categories added in Perl 5.019 */
98
99 #define WARN_EXPERIMENTAL__POSTDEREF     55
100 #define WARN_EXPERIMENTAL__SIGNATURES    56
101 #define WARN_SYSCALLS                    57
102
103 /* Warnings Categories added in Perl 5.021 */
104
105 #define WARN_EXPERIMENTAL__BITWISE       58
106 #define WARN_EXPERIMENTAL__CONST_ATTR    59
107 #define WARN_EXPERIMENTAL__RE_STRICT     60
108 #define WARN_EXPERIMENTAL__REFALIASING   61
109 #define WARN_EXPERIMENTAL__WIN32_PERLIO  62
110 #define WARN_LOCALE                      63
111 #define WARN_MISSING                     64
112 #define WARN_REDUNDANT                   65
113
114 /* Warnings Categories added in Perl 5.025 */
115
116 #define WARN_EXPERIMENTAL__DECLARED_REFS 66
117
118 /* Warnings Categories added in Perl 5.027 */
119
120 #define WARN_EXPERIMENTAL__ALPHA_ASSERTIONS 67
121 #define WARN_EXPERIMENTAL__SCRIPT_RUN    68
122 #define WARN_SHADOW                      69
123
124 /* Warnings Categories added in Perl 5.029 */
125
126 #define WARN_EXPERIMENTAL__PRIVATE_USE   70
127 #define WARN_EXPERIMENTAL__UNIPROP_WILDCARDS 71
128 #define WARN_EXPERIMENTAL__VLB           72
129
130
131 /*
132 =for apidoc Amnh||WARN_ALL
133 =for apidoc Amnh||WARN_CLOSURE
134 =for apidoc Amnh||WARN_DEPRECATED
135 =for apidoc Amnh||WARN_EXITING
136 =for apidoc Amnh||WARN_GLOB
137 =for apidoc Amnh||WARN_IO
138 =for apidoc Amnh||WARN_CLOSED
139 =for apidoc Amnh||WARN_EXEC
140 =for apidoc Amnh||WARN_LAYER
141 =for apidoc Amnh||WARN_NEWLINE
142 =for apidoc Amnh||WARN_PIPE
143 =for apidoc Amnh||WARN_UNOPENED
144 =for apidoc Amnh||WARN_MISC
145 =for apidoc Amnh||WARN_NUMERIC
146 =for apidoc Amnh||WARN_ONCE
147 =for apidoc Amnh||WARN_OVERFLOW
148 =for apidoc Amnh||WARN_PACK
149 =for apidoc Amnh||WARN_PORTABLE
150 =for apidoc Amnh||WARN_RECURSION
151 =for apidoc Amnh||WARN_REDEFINE
152 =for apidoc Amnh||WARN_REGEXP
153 =for apidoc Amnh||WARN_SEVERE
154 =for apidoc Amnh||WARN_DEBUGGING
155 =for apidoc Amnh||WARN_INPLACE
156 =for apidoc Amnh||WARN_INTERNAL
157 =for apidoc Amnh||WARN_MALLOC
158 =for apidoc Amnh||WARN_SIGNAL
159 =for apidoc Amnh||WARN_SUBSTR
160 =for apidoc Amnh||WARN_SYNTAX
161 =for apidoc Amnh||WARN_AMBIGUOUS
162 =for apidoc Amnh||WARN_BAREWORD
163 =for apidoc Amnh||WARN_DIGIT
164 =for apidoc Amnh||WARN_PARENTHESIS
165 =for apidoc Amnh||WARN_PRECEDENCE
166 =for apidoc Amnh||WARN_PRINTF
167 =for apidoc Amnh||WARN_PROTOTYPE
168 =for apidoc Amnh||WARN_QW
169 =for apidoc Amnh||WARN_RESERVED
170 =for apidoc Amnh||WARN_SEMICOLON
171 =for apidoc Amnh||WARN_TAINT
172 =for apidoc Amnh||WARN_THREADS
173 =for apidoc Amnh||WARN_UNINITIALIZED
174 =for apidoc Amnh||WARN_UNPACK
175 =for apidoc Amnh||WARN_UNTIE
176 =for apidoc Amnh||WARN_UTF8
177 =for apidoc Amnh||WARN_VOID
178 =for apidoc Amnh||WARN_IMPRECISION
179 =for apidoc Amnh||WARN_ILLEGALPROTO
180 =for apidoc Amnh||WARN_NON_UNICODE
181 =for apidoc Amnh||WARN_NONCHAR
182 =for apidoc Amnh||WARN_SURROGATE
183 =for apidoc Amnh||WARN_EXPERIMENTAL
184 =for apidoc Amnh||WARN_EXPERIMENTAL__LEXICAL_SUBS
185 =for apidoc Amnh||WARN_EXPERIMENTAL__REGEX_SETS
186 =for apidoc Amnh||WARN_EXPERIMENTAL__SMARTMATCH
187 =for apidoc Amnh||WARN_EXPERIMENTAL__POSTDEREF
188 =for apidoc Amnh||WARN_EXPERIMENTAL__SIGNATURES
189 =for apidoc Amnh||WARN_SYSCALLS
190 =for apidoc Amnh||WARN_EXPERIMENTAL__BITWISE
191 =for apidoc Amnh||WARN_EXPERIMENTAL__CONST_ATTR
192 =for apidoc Amnh||WARN_EXPERIMENTAL__RE_STRICT
193 =for apidoc Amnh||WARN_EXPERIMENTAL__REFALIASING
194 =for apidoc Amnh||WARN_EXPERIMENTAL__WIN32_PERLIO
195 =for apidoc Amnh||WARN_LOCALE
196 =for apidoc Amnh||WARN_MISSING
197 =for apidoc Amnh||WARN_REDUNDANT
198 =for apidoc Amnh||WARN_EXPERIMENTAL__DECLARED_REFS
199 =for apidoc Amnh||WARN_EXPERIMENTAL__ALPHA_ASSERTIONS
200 =for apidoc Amnh||WARN_EXPERIMENTAL__SCRIPT_RUN
201 =for apidoc Amnh||WARN_SHADOW
202 =for apidoc Amnh||WARN_EXPERIMENTAL__PRIVATE_USE
203 =for apidoc Amnh||WARN_EXPERIMENTAL__UNIPROP_WILDCARDS
204 =for apidoc Amnh||WARN_EXPERIMENTAL__VLB
205
206 =cut
207 */
208
209 #define WARNsize                         19
210 #define WARN_ALLstring                   "\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125"
211 #define WARN_NONEstring                  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
212
213 #define isLEXWARN_on \
214         cBOOL(PL_curcop && PL_curcop->cop_warnings != pWARN_STD)
215 #define isLEXWARN_off \
216         cBOOL(!PL_curcop || PL_curcop->cop_warnings == pWARN_STD)
217 #define isWARN_ONCE     (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
218 #define isWARN_on(c,x)  (IsSet((U8 *)(c + 1), 2*(x)))
219 #define isWARNf_on(c,x) (IsSet((U8 *)(c + 1), 2*(x)+1))
220
221 #define DUP_WARNINGS(p) Perl_dup_warnings(aTHX_ p)
222
223 /*
224
225 =head1 Warning and Dieing
226
227 In all these calls, the C<U32 wI<n>> parameters are warning category
228 constants.  You can see the ones currently available in
229 L<warnings/Category Hierarchy>, just capitalize all letters in the names
230 and prefix them by C<WARN_>.  So, for example, the category C<void> used in a
231 perl program becomes C<WARN_VOID> when used in XS code and passed to one of
232 the calls below.
233
234 =for apidoc Am|bool|ckWARN|U32 w
235
236 Returns a boolean as to whether or not warnings are enabled for the warning
237 category C<w>.  If the category is by default enabled even if not within the
238 scope of S<C<use warnings>>, instead use the L</ckWARN_d> macro.
239
240 =for apidoc Am|bool|ckWARN_d|U32 w
241
242 Like C<L</ckWARN>>, but for use if and only if the warning category is by
243 default enabled even if not within the scope of S<C<use warnings>>.
244
245 =for apidoc Am|bool|ckWARN2|U32 w1|U32 w2
246
247 Like C<L</ckWARN>>, but takes two warnings categories as input, and returns
248 TRUE if either is enabled.  If either category is by default enabled even if
249 not within the scope of S<C<use warnings>>, instead use the L</ckWARN2_d>
250 macro.  The categories must be completely independent, one may not be
251 subclassed from the other.
252
253 =for apidoc Am|bool|ckWARN2_d|U32 w1|U32 w2
254
255 Like C<L</ckWARN2>>, but for use if and only if either warning category is by
256 default enabled even if not within the scope of S<C<use warnings>>.
257
258 =for apidoc Am|bool|ckWARN3|U32 w1|U32 w2|U32 w3
259
260 Like C<L</ckWARN2>>, but takes three warnings categories as input, and returns
261 TRUE if any is enabled.  If any of the categories is by default enabled even
262 if not within the scope of S<C<use warnings>>, instead use the L</ckWARN3_d>
263 macro.  The categories must be completely independent, one may not be
264 subclassed from any other.
265
266 =for apidoc Am|bool|ckWARN3_d|U32 w1|U32 w2|U32 w3
267
268 Like C<L</ckWARN3>>, but for use if and only if any of the warning categories
269 is by default enabled even if not within the scope of S<C<use warnings>>.
270
271 =for apidoc Am|bool|ckWARN4|U32 w1|U32 w2|U32 w3|U32 w4
272
273 Like C<L</ckWARN3>>, but takes four warnings categories as input, and returns
274 TRUE if any is enabled.  If any of the categories is by default enabled even
275 if not within the scope of S<C<use warnings>>, instead use the L</ckWARN4_d>
276 macro.  The categories must be completely independent, one may not be
277 subclassed from any other.
278
279 =for apidoc Am|bool|ckWARN4_d|U32 w1|U32 w2|U32 w3|U32 w4
280
281 Like C<L</ckWARN4>>, but for use if and only if any of the warning categories
282 is by default enabled even if not within the scope of S<C<use warnings>>.
283
284 =cut
285
286 */
287
288 #define ckWARN(w)               Perl_ckwarn(aTHX_ packWARN(w))
289
290 /* The w1, w2 ... should be independent warnings categories; one shouldn't be
291  * a subcategory of any other */
292
293 #define ckWARN2(w1,w2)          Perl_ckwarn(aTHX_ packWARN2(w1,w2))
294 #define ckWARN3(w1,w2,w3)       Perl_ckwarn(aTHX_ packWARN3(w1,w2,w3))
295 #define ckWARN4(w1,w2,w3,w4)    Perl_ckwarn(aTHX_ packWARN4(w1,w2,w3,w4))
296
297 #define ckWARN_d(w)             Perl_ckwarn_d(aTHX_ packWARN(w))
298 #define ckWARN2_d(w1,w2)        Perl_ckwarn_d(aTHX_ packWARN2(w1,w2))
299 #define ckWARN3_d(w1,w2,w3)     Perl_ckwarn_d(aTHX_ packWARN3(w1,w2,w3))
300 #define ckWARN4_d(w1,w2,w3,w4)  Perl_ckwarn_d(aTHX_ packWARN4(w1,w2,w3,w4))
301
302 #define WARNshift               8
303
304 #define packWARN(a)             (a                                      )
305
306 /* The a, b, ... should be independent warnings categories; one shouldn't be
307  * a subcategory of any other */
308
309 #define packWARN2(a,b)          ((a) | ((b)<<8)                         )
310 #define packWARN3(a,b,c)        ((a) | ((b)<<8) | ((c)<<16)             )
311 #define packWARN4(a,b,c,d)      ((a) | ((b)<<8) | ((c)<<16) | ((d) <<24))
312
313 #define unpackWARN1(x)          ((x)        & 0xFF)
314 #define unpackWARN2(x)          (((x) >>8)  & 0xFF)
315 #define unpackWARN3(x)          (((x) >>16) & 0xFF)
316 #define unpackWARN4(x)          (((x) >>24) & 0xFF)
317
318 #define ckDEAD(x)                                                       \
319    (PL_curcop &&                                                        \
320     !specialWARN(PL_curcop->cop_warnings) &&                            \
321     (isWARNf_on(PL_curcop->cop_warnings, unpackWARN1(x)) ||             \
322       (unpackWARN2(x) &&                                                \
323         (isWARNf_on(PL_curcop->cop_warnings, unpackWARN2(x)) ||         \
324           (unpackWARN3(x) &&                                            \
325             (isWARNf_on(PL_curcop->cop_warnings, unpackWARN3(x)) ||     \
326               (unpackWARN4(x) &&                                        \
327                 isWARNf_on(PL_curcop->cop_warnings, unpackWARN4(x)))))))))
328
329 /* end of file warnings.h */
330
331 /* ex: set ro: */