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!
10 # Verify that we're called correctly so that warnings will work.
11 # Can't use Carp, since Carp uses us!
12 # String regexps because constant folding = smaller optree = less memory vs regexp literal
14 die sprintf "Incorrect use of pragma '%s' at %s line %d.\n", __PACKAGE__, +(caller)[1,2]
15 if __FILE__ !~ ( '(?x) \b '.__PACKAGE__.' \.pmc? \z' )
16 && __FILE__ =~ ( '(?x) \b (?i:'.__PACKAGE__.') \.pmc? \z' );
19 # Warnings Categories added in Perl 5.008
61 'uninitialized' => 82,
67 # Warnings Categories added in Perl 5.011
71 # Warnings Categories added in Perl 5.013
76 # Warnings Categories added in Perl 5.017
77 'experimental' => 102,
78 'experimental::lexical_subs' => 104,
79 'experimental::regex_sets' => 106,
80 'experimental::smartmatch' => 108,
82 # Warnings Categories added in Perl 5.019
83 'experimental::postderef' => 110,
84 'experimental::signatures' => 112,
87 # Warnings Categories added in Perl 5.021
88 'experimental::bitwise' => 116,
89 'experimental::const_attr' => 118,
90 'experimental::re_strict' => 120,
91 'experimental::refaliasing' => 122,
92 'experimental::win32_perlio' => 124,
97 # Warnings Categories added in Perl 5.025
98 'experimental::declared_refs' => 132,
100 # Warnings Categories added in Perl 5.027
105 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..67]
106 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
107 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
108 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
109 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
110 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
111 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
112 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
113 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
114 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
115 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x51\x15\x10", # [51..56,58..62,66]
116 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [58]
117 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [59]
118 'experimental::declared_refs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [66]
119 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [52]
120 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [55]
121 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [60]
122 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [61]
123 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [53]
124 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [56]
125 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [54]
126 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [62]
127 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
128 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [47]
129 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [46]
130 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
131 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
132 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [5..11,57]
133 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
134 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [63]
135 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
136 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
137 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [64]
138 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
139 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [48]
140 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [49]
141 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
142 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
143 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
144 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
145 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
146 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
147 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
148 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
149 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
150 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
151 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [36]
152 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
153 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
154 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [65]
155 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
156 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [37]
157 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [38]
158 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
159 'shadow' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [67]
160 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
161 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
162 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [50]
163 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00", # [28..38,47]
164 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [57]
165 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [39]
166 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [40]
167 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [41]
168 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
169 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [42]
170 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [43]
171 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00\x00", # [44,48..50]
172 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [45]
176 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..67]
177 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
178 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
179 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
180 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
181 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
182 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
183 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
184 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
185 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
186 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\xa2\x2a\x20", # [51..56,58..62,66]
187 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [58]
188 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [59]
189 'experimental::declared_refs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [66]
190 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [52]
191 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [55]
192 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [60]
193 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [61]
194 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [53]
195 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [56]
196 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [54]
197 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [62]
198 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
199 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [47]
200 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [46]
201 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
202 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
203 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [5..11,57]
204 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
205 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [63]
206 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
207 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
208 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [64]
209 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
210 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [48]
211 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [49]
212 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
213 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
214 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
215 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
216 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
217 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
218 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
219 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
220 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
221 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
222 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [36]
223 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
224 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
225 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [65]
226 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
227 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [37]
228 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [38]
229 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
230 'shadow' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [67]
231 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
232 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
233 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [50]
234 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00", # [28..38,47]
235 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [57]
236 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [39]
237 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [40]
238 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [41]
239 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
240 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [42]
241 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [43]
242 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00\x00", # [44,48..50]
243 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [45]
246 # These are used by various things, including our own tests
247 our $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
248 our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x51\x55\x10", # [2,4,22,23,25,52..56,58..63,66]
249 our $LAST_BIT = 136 ;
254 require Carp; # this initializes %CarpInternal
255 local $Carp::CarpInternal{'warnings'};
256 delete $Carp::CarpInternal{'warnings'};
262 my $want_len = ($LAST_BIT + 7) >> 3;
263 my $len = length($bits);
264 if ($len != $want_len) {
266 $bits = "\x00" x $want_len;
267 } elsif ($len > $want_len) {
268 substr $bits, $want_len, $len-$want_len, "";
270 my $a = vec($bits, $Offsets{all} >> 1, 2);
273 $bits .= chr($a) x ($want_len - $len);
285 $mask = _expand_bits($mask);
286 foreach my $word ( @_ ) {
287 if ($word eq 'FATAL') {
291 elsif ($word eq 'NONFATAL') {
295 elsif ($catmask = $Bits{$word}) {
297 $mask |= $DeadBits{$word} if $fatal ;
298 $mask = ~(~$mask | $DeadBits{$word}) if $no_fatal ;
301 { Croaker("Unknown warnings category '$word'")}
309 # called from B::Deparse.pm
310 push @_, 'all' unless @_ ;
311 return _bits("", @_) ;
318 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
320 # append 'all' when implied (empty import list or after a lone
321 # "FATAL" or "NONFATAL")
323 if !@_ || (@_==1 && ($_[0] eq 'FATAL' || $_[0] eq 'NONFATAL'));
325 ${^WARNING_BITS} = _bits($mask, @_);
333 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
335 # append 'all' when implied (empty import list or after a lone "FATAL")
336 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
338 $mask = _expand_bits($mask);
339 foreach my $word ( @_ ) {
340 if ($word eq 'FATAL') {
343 elsif ($catmask = $Bits{$word}) {
344 $mask = ~(~$mask | $catmask | $DeadBits{$word});
347 { Croaker("Unknown warnings category '$word'")}
350 ${^WARNING_BITS} = $mask ;
353 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
355 sub MESSAGE () { 4 };
365 my $has_message = $wanted & MESSAGE;
367 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
368 my $sub = (caller 1)[3];
369 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
370 Croaker("Usage: $sub($syntax)");
373 my $message = pop if $has_message;
376 # check the category supplied.
378 if (my $type = ref $category) {
379 Croaker("not an object")
380 if exists $builtin_type{$type};
384 $offset = $Offsets{$category};
385 Croaker("Unknown warnings category '$category'")
386 unless defined $offset;
389 $category = (caller(1))[0] ;
390 $offset = $Offsets{$category};
391 Croaker("package '$category' not registered for warnings")
392 unless defined $offset ;
400 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
401 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
406 $i = _error_loc(); # see where Carp will allocate the error
409 # Default to 0 if caller returns nothing. Default to $DEFAULT if it
410 # explicitly returns undef.
411 my(@callers_bitmask) = (caller($i))[9] ;
412 my $callers_bitmask =
413 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
414 length($callers_bitmask) > ($offset >> 3) or $offset = $Offsets{all};
417 foreach my $type (FATAL, NORMAL) {
418 next unless $wanted & $type;
420 push @results, vec($callers_bitmask, $offset + $type - 1, 1);
423 # &enabled and &fatal_enabled
424 return $results[0] unless $has_message;
426 # &warnif, and the category is neither enabled as warning nor as fatal
427 return if $wanted == (NORMAL | FATAL | MESSAGE)
428 && !($results[0] || $results[1]);
431 Carp::croak($message) if $results[0];
432 # will always get here for &warn. will only get here for &warnif if the
433 # category is enabled
434 Carp::carp($message);
442 vec($mask, $bit, 1) = 1;
446 sub register_categories
450 for my $name (@names) {
451 if (! defined $Bits{$name}) {
452 $Offsets{$name} = $LAST_BIT;
453 $Bits{$name} = _mkMask($LAST_BIT++);
454 $DeadBits{$name} = _mkMask($LAST_BIT++);
455 if (length($Bits{$name}) > length($Bits{all})) {
456 $Bits{all} .= "\x55";
457 $DeadBits{all} .= "\xaa";
465 goto &Carp::short_error_loc; # don't introduce another stack frame
470 return __chk(NORMAL, @_);
475 return __chk(FATAL, @_);
480 return __chk(FATAL | MESSAGE, @_);
485 return __chk(NORMAL | FATAL | MESSAGE, @_);
488 # These are not part of any public interface, so we can delete them to save
490 delete @warnings::{qw(NORMAL FATAL MESSAGE)};
496 warnings - Perl pragma to control optional warnings
506 use warnings::register;
507 if (warnings::enabled()) {
508 warnings::warn("some warning");
511 if (warnings::enabled("void")) {
512 warnings::warn("void", "some warning");
515 if (warnings::enabled($object)) {
516 warnings::warn($object, "some warning");
519 warnings::warnif("some warning");
520 warnings::warnif("void", "some warning");
521 warnings::warnif($object, "some warning");
525 The C<warnings> pragma gives control over which warnings are enabled in
526 which parts of a Perl program. It's a more flexible alternative for
527 both the command line flag B<-w> and the equivalent Perl variable,
530 This pragma works just like the C<strict> pragma.
531 This means that the scope of the warning pragma is limited to the
532 enclosing block. It also means that the pragma setting will not
533 leak across files (via C<use>, C<require> or C<do>). This allows
534 authors to independently define the degree of warning checks that will
535 be applied to their module.
537 By default, optional warnings are disabled, so any legacy code that
538 doesn't attempt to control the warnings will work unchanged.
540 All warnings are enabled in a block by either of these:
545 Similarly all warnings are disabled in a block by either of these:
550 For example, consider the code below:
560 The code in the enclosing block has warnings enabled, but the inner
561 block has them disabled. In this case that means the assignment to the
562 scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
563 warning, but the assignment to the scalar C<$b> will not.
565 =head2 Default Warnings and Optional Warnings
567 Before the introduction of lexical warnings, Perl had two classes of
568 warnings: mandatory and optional.
570 As its name suggests, if your code tripped a mandatory warning, you
571 would get a warning whether you wanted it or not.
572 For example, the code below would always produce an C<"isn't numeric">
573 warning about the "2:".
577 With the introduction of lexical warnings, mandatory warnings now become
578 I<default> warnings. The difference is that although the previously
579 mandatory warnings are still enabled by default, they can then be
580 subsequently enabled or disabled with the lexical warning pragma. For
581 example, in the code below, an C<"isn't numeric"> warning will only
582 be reported for the C<$a> variable.
588 Note that neither the B<-w> flag or the C<$^W> can be used to
589 disable/enable default warnings. They are still mandatory in this case.
591 =head2 What's wrong with B<-w> and C<$^W>
593 Although very useful, the big problem with using B<-w> on the command
594 line to enable warnings is that it is all or nothing. Take the typical
595 scenario when you are writing a Perl program. Parts of the code you
596 will write yourself, but it's very likely that you will make use of
597 pre-written Perl modules. If you use the B<-w> flag in this case, you
598 end up enabling warnings in pieces of code that you haven't written.
600 Similarly, using C<$^W> to either disable or enable blocks of code is
601 fundamentally flawed. For a start, say you want to disable warnings in
602 a block of code. You might expect this to be enough to do the trick:
610 When this code is run with the B<-w> flag, a warning will be produced
611 for the C<$a> line: C<"Reversed += operator">.
613 The problem is that Perl has both compile-time and run-time warnings. To
614 disable compile-time warnings you need to rewrite the code like this:
622 The other big problem with C<$^W> is the way you can inadvertently
623 change the warning setting in unexpected places in your code. For example,
624 when the code below is run (without the B<-w> flag), the second call
625 to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
640 This is a side-effect of C<$^W> being dynamically scoped.
642 Lexical warnings get around these limitations by allowing finer control
643 over where warnings can or can't be tripped.
645 =head2 Controlling Warnings from the Command Line
647 There are three Command Line flags that can be used to control when
648 warnings are (or aren't) produced:
655 This is the existing flag. If the lexical warnings pragma is B<not>
656 used in any of you code, or any of the modules that you use, this flag
657 will enable warnings everywhere. See L<Backward Compatibility> for
658 details of how this flag interacts with lexical warnings.
663 If the B<-W> flag is used on the command line, it will enable all warnings
664 throughout the program regardless of whether warnings were disabled
665 locally using C<no warnings> or C<$^W =0>.
666 This includes all files that get
667 included via C<use>, C<require> or C<do>.
668 Think of it as the Perl equivalent of the "lint" command.
673 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
677 =head2 Backward Compatibility
679 If you are used to working with a version of Perl prior to the
680 introduction of lexically scoped warnings, or have code that uses both
681 lexical warnings and C<$^W>, this section will describe how they interact.
683 How Lexical Warnings interact with B<-w>/C<$^W>:
689 If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
690 control warnings is used and neither C<$^W> nor the C<warnings> pragma
691 are used, then default warnings will be enabled and optional warnings
693 This means that legacy code that doesn't attempt to control the warnings
698 The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
699 means that any legacy code that currently relies on manipulating C<$^W>
700 to control warning behavior will still work as is.
704 Apart from now being a boolean, the C<$^W> variable operates in exactly
705 the same horrible uncontrolled global way, except that it cannot
706 disable/enable default warnings.
710 If a piece of code is under the control of the C<warnings> pragma,
711 both the C<$^W> variable and the B<-w> flag will be ignored for the
712 scope of the lexical warning.
716 The only way to override a lexical warnings setting is with the B<-W>
717 or B<-X> command line flags.
721 The combined effect of 3 & 4 is that it will allow code which uses
722 the C<warnings> pragma to control the warning behavior of $^W-type
723 code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
725 =head2 Category Hierarchy
726 X<warning, categories>
728 A hierarchy of "categories" have been defined to allow groups of warnings
729 to be enabled/disabled in isolation.
731 The current hierarchy is:
743 | +- experimental::bitwise
745 | +- experimental::const_attr
747 | +- experimental::declared_refs
749 | +- experimental::lexical_subs
751 | +- experimental::postderef
753 | +- experimental::re_strict
755 | +- experimental::refaliasing
757 | +- experimental::regex_sets
759 | +- experimental::signatures
761 | +- experimental::smartmatch
763 | +- experimental::win32_perlio
869 Just like the "strict" pragma any of these categories can be combined
871 use warnings qw(void redefine);
872 no warnings qw(io syntax untie);
874 Also like the "strict" pragma, if there is more than one instance of the
875 C<warnings> pragma in a given scope the cumulative effect is additive.
877 use warnings qw(void); # only "void" warnings enabled
879 use warnings qw(io); # only "void" & "io" warnings enabled
881 no warnings qw(void); # only "io" warnings enabled
883 To determine which category a specific warning has been assigned to see
886 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
887 sub-category of the "syntax" category. It is now a top-level category
890 Note: Before 5.21.0, the "missing" lexical warnings category was
891 internally defined to be the same as the "uninitialized" category. It
892 is now a top-level category in its own right.
894 =head2 Fatal Warnings
897 The presence of the word "FATAL" in the category list will escalate
898 warnings in those categories into fatal errors in that lexical scope.
900 B<NOTE:> FATAL warnings should be used with care, particularly
901 C<< FATAL => 'all' >>.
903 Libraries using L<warnings::warn|/FUNCTIONS> for custom warning categories
904 generally don't expect L<warnings::warn|/FUNCTIONS> to be fatal and can wind up
905 in an unexpected state as a result. For XS modules issuing categorized
906 warnings, such unanticipated exceptions could also expose memory leak bugs.
908 Moreover, the Perl interpreter itself has had serious bugs involving
909 fatalized warnings. For a summary of resolved and unresolved problems as
910 of January 2015, please see
911 L<this perl5-porters post|http://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225235.html>.
913 While some developers find fatalizing some warnings to be a useful
914 defensive programming technique, using C<< FATAL => 'all' >> to fatalize
915 all possible warning categories -- including custom ones -- is particularly
916 risky. Therefore, the use of C<< FATAL => 'all' >> is
917 L<discouraged|perlpolicy/discouraged>.
919 The L<strictures|strictures/VERSION-2> module on CPAN offers one example of
920 a warnings subset that the module's authors believe is relatively safe to
923 B<NOTE:> users of FATAL warnings, especially those using
924 C<< FATAL => 'all' >>, should be fully aware that they are risking future
925 portability of their programs by doing so. Perl makes absolutely no
926 commitments to not introduce new warnings or warnings categories in the
927 future; indeed, we explicitly reserve the right to do so. Code that may
928 not warn now may warn in a future release of Perl if the Perl5 development
929 team deems it in the best interests of the community to do so. Should code
930 using FATAL warnings break due to the introduction of a new warning we will
931 NOT consider it an incompatible change. Users of FATAL warnings should
932 take special caution during upgrades to check to see if their code triggers
933 any new warnings and should pay particular attention to the fine print of
934 the documentation of the features they use to ensure they do not exploit
935 features that are documented as risky, deprecated, or unspecified, or where
936 the documentation says "so don't do that", or anything with the same sense
937 and spirit. Use of such features in combination with FATAL warnings is
938 ENTIRELY AT THE USER'S RISK.
940 The following documentation describes how to use FATAL warnings but the
941 perl5 porters strongly recommend that you understand the risks before doing
942 so, especially for library code intended for use by others, as there is no
943 way for downstream users to change the choice of fatal categories.
945 In the code below, the use of C<time>, C<length>
946 and C<join> can all produce a C<"Useless use of xxx in void context">
954 use warnings FATAL => qw(void);
962 When run it produces this output
964 Useless use of time in void context at fatal line 3.
965 Useless use of length in void context at fatal line 7.
967 The scope where C<length> is used has escalated the C<void> warnings
968 category into a fatal error, so the program terminates immediately when it
969 encounters the warning.
971 To explicitly turn off a "FATAL" warning you just disable the warning
972 it is associated with. So, for example, to disable the "void" warning
973 in the example above, either of these will do the trick:
975 no warnings qw(void);
976 no warnings FATAL => qw(void);
978 If you want to downgrade a warning that has been escalated into a fatal
979 error back to a normal warning, you can use the "NONFATAL" keyword. For
980 example, the code below will promote all warnings into fatal errors,
981 except for those in the "syntax" category.
983 use warnings FATAL => 'all', NONFATAL => 'syntax';
985 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
988 use v5.20; # Perl 5.20 or greater is required for the following
989 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
991 If you want your program to be compatible with versions of Perl before
992 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
993 previous versions of Perl, the behavior of the statements
994 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
995 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
996 they included the C<< => 'all' >> portion. As of 5.20, they do.)
998 =head2 Reporting Warnings from a Module
999 X<warning, reporting> X<warning, registering>
1001 The C<warnings> pragma provides a number of functions that are useful for
1002 module authors. These are used when you want to report a module-specific
1003 warning to a calling module has enabled warnings via the C<warnings>
1006 Consider the module C<MyMod::Abc> below.
1010 use warnings::register;
1014 if ($path !~ m#^/#) {
1015 warnings::warn("changing relative path to /var/abc")
1016 if warnings::enabled();
1017 $path = "/var/abc/$path";
1023 The call to C<warnings::register> will create a new warnings category
1024 called "MyMod::Abc", i.e. the new category name matches the current
1025 package name. The C<open> function in the module will display a warning
1026 message if it gets given a relative path as a parameter. This warnings
1027 will only be displayed if the code that uses C<MyMod::Abc> has actually
1028 enabled them with the C<warnings> pragma like below.
1031 use warnings 'MyMod::Abc';
1033 abc::open("../fred.txt");
1035 It is also possible to test whether the pre-defined warnings categories are
1036 set in the calling module with the C<warnings::enabled> function. Consider
1037 this snippet of code:
1042 if (warnings::enabled("deprecated")) {
1043 warnings::warn("deprecated",
1044 "open is deprecated, use new instead");
1053 The function C<open> has been deprecated, so code has been included to
1054 display a warning message whenever the calling module has (at least) the
1055 "deprecated" warnings category enabled. Something like this, say.
1057 use warnings 'deprecated';
1060 MyMod::Abc::open($filename);
1062 Either the C<warnings::warn> or C<warnings::warnif> function should be
1063 used to actually display the warnings message. This is because they can
1064 make use of the feature that allows warnings to be escalated into fatal
1065 errors. So in this case
1068 use warnings FATAL => 'MyMod::Abc';
1070 MyMod::Abc::open('../fred.txt');
1072 the C<warnings::warnif> function will detect this and die after
1073 displaying the warning message.
1075 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
1076 and C<warnings::enabled> can optionally take an object reference in place
1077 of a category name. In this case the functions will use the class name
1078 of the object as the warnings category.
1080 Consider this example:
1085 use warnings::register;
1098 if ($value % 2 && warnings::enabled($self))
1099 { warnings::warn($self, "Odd numbers are unsafe") }
1106 $self->check($value);
1114 use warnings::register;
1116 our @ISA = qw( Original );
1126 The code below makes use of both modules, but it only enables warnings from
1131 use warnings 'Derived';
1132 my $a = Original->new();
1134 my $b = Derived->new();
1137 When this code is run only the C<Derived> object, C<$b>, will generate
1140 Odd numbers are unsafe at main.pl line 7
1142 Notice also that the warning is reported at the line where the object is first
1145 When registering new categories of warning, you can supply more names to
1146 warnings::register like this:
1149 use warnings::register qw(format precision);
1153 warnings::warnif('MyModule::format', '...');
1159 =item use warnings::register
1161 Creates a new warnings category with the same name as the package where
1162 the call to the pragma is used.
1164 =item warnings::enabled()
1166 Use the warnings category with the same name as the current package.
1168 Return TRUE if that warnings category is enabled in the calling module.
1169 Otherwise returns FALSE.
1171 =item warnings::enabled($category)
1173 Return TRUE if the warnings category, C<$category>, is enabled in the
1175 Otherwise returns FALSE.
1177 =item warnings::enabled($object)
1179 Use the name of the class for the object reference, C<$object>, as the
1182 Return TRUE if that warnings category is enabled in the first scope
1183 where the object is used.
1184 Otherwise returns FALSE.
1186 =item warnings::fatal_enabled()
1188 Return TRUE if the warnings category with the same name as the current
1189 package has been set to FATAL in the calling module.
1190 Otherwise returns FALSE.
1192 =item warnings::fatal_enabled($category)
1194 Return TRUE if the warnings category C<$category> has been set to FATAL in
1196 Otherwise returns FALSE.
1198 =item warnings::fatal_enabled($object)
1200 Use the name of the class for the object reference, C<$object>, as the
1203 Return TRUE if that warnings category has been set to FATAL in the first
1204 scope where the object is used.
1205 Otherwise returns FALSE.
1207 =item warnings::warn($message)
1209 Print C<$message> to STDERR.
1211 Use the warnings category with the same name as the current package.
1213 If that warnings category has been set to "FATAL" in the calling module
1214 then die. Otherwise return.
1216 =item warnings::warn($category, $message)
1218 Print C<$message> to STDERR.
1220 If the warnings category, C<$category>, has been set to "FATAL" in the
1221 calling module then die. Otherwise return.
1223 =item warnings::warn($object, $message)
1225 Print C<$message> to STDERR.
1227 Use the name of the class for the object reference, C<$object>, as the
1230 If that warnings category has been set to "FATAL" in the scope where C<$object>
1231 is first used then die. Otherwise return.
1234 =item warnings::warnif($message)
1238 if (warnings::enabled())
1239 { warnings::warn($message) }
1241 =item warnings::warnif($category, $message)
1245 if (warnings::enabled($category))
1246 { warnings::warn($category, $message) }
1248 =item warnings::warnif($object, $message)
1252 if (warnings::enabled($object))
1253 { warnings::warn($object, $message) }
1255 =item warnings::register_categories(@names)
1257 This registers warning categories for the given names and is primarily for
1258 use by the warnings::register pragma.
1262 See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.