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.
12 unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
13 my (undef, $f, $l) = caller;
14 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
19 # Warnings Categories added in Perl 5.008
62 'uninitialized' => 82,
68 # Warnings Categories added in Perl 5.011
73 # Warnings Categories added in Perl 5.013
79 # Warnings Categories added in Perl 5.017
81 'experimental' => 102,
82 'experimental::lexical_subs'=> 104,
83 'experimental::lexical_topic'=> 106,
84 'experimental::regex_sets'=> 108,
85 'experimental::smartmatch'=> 110,
87 # Warnings Categories added in Perl 5.019
89 'experimental::autoderef'=> 112,
90 'experimental::postderef'=> 114,
91 'experimental::signatures'=> 116,
94 # Warnings Categories added in Perl 5.021
96 'experimental::refaliasing'=> 120,
97 'experimental::win32_perlio'=> 122,
104 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x01", # [0..64]
105 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
106 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
107 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
108 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
109 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
110 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
111 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
112 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
113 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
114 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x15\x05\x00", # [51..58,60,61]
115 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [56]
116 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [52]
117 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [53]
118 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [57]
119 'experimental::refaliasing'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [60]
120 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [54]
121 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [58]
122 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [55]
123 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [61]
124 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
125 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [47]
126 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [46]
127 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
128 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
129 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [5..11,59]
130 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
131 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [62]
132 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
133 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
134 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [63]
135 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
136 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [48]
137 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [49]
138 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
139 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
140 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
141 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
142 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
143 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
144 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
145 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
146 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
147 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
148 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [36]
149 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
150 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
151 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [64]
152 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
153 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [37]
154 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [38]
155 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
156 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
157 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
158 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [50]
159 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00", # [28..38,47]
160 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [59]
161 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [39]
162 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [40]
163 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [41]
164 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
165 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [42]
166 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [43]
167 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00\x00", # [44,48..50]
168 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [45]
172 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x02", # [0..64]
173 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
174 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
175 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
176 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
177 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
178 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
179 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
180 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
181 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
182 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\x2a\x0a\x00", # [51..58,60,61]
183 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [56]
184 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [52]
185 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [53]
186 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [57]
187 'experimental::refaliasing'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [60]
188 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [54]
189 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [58]
190 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [55]
191 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [61]
192 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
193 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [47]
194 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [46]
195 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
196 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
197 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [5..11,59]
198 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
199 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [62]
200 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
201 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
202 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [63]
203 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
204 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [48]
205 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [49]
206 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
207 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
208 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
209 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
210 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
211 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
212 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
213 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
214 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
215 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
216 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [36]
217 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
218 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
219 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [64]
220 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
221 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [37]
222 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [38]
223 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
224 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
225 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
226 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [50]
227 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00", # [28..38,47]
228 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [59]
229 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [39]
230 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [40]
231 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [41]
232 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
233 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [42]
234 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [43]
235 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00\x00", # [44,48..50]
236 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [45]
239 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
240 $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x15\x15\x00", # [2,56,52,53,57,60,54,58,55,61,4,62,22,23,25]
244 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
248 require Carp; # this initializes %CarpInternal
249 local $Carp::CarpInternal{'warnings'};
250 delete $Carp::CarpInternal{'warnings'};
260 foreach my $word ( @_ ) {
261 if ($word eq 'FATAL') {
265 elsif ($word eq 'NONFATAL') {
269 elsif ($catmask = $Bits{$word}) {
271 $mask |= $DeadBits{$word} if $fatal ;
272 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
275 { Croaker("Unknown warnings category '$word'")}
283 # called from B::Deparse.pm
284 push @_, 'all' unless @_ ;
285 return _bits(undef, @_) ;
292 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
294 if (vec($mask, $Offsets{'all'}, 1)) {
295 $mask |= $Bits{'all'} ;
296 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
299 # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
300 push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
302 # Empty @_ is equivalent to @_ = 'all' ;
303 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
311 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
313 if (vec($mask, $Offsets{'all'}, 1)) {
314 $mask |= $Bits{'all'} ;
315 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
318 # append 'all' when implied (empty import list or after a lone "FATAL")
319 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
321 foreach my $word ( @_ ) {
322 if ($word eq 'FATAL') {
325 elsif ($catmask = $Bits{$word}) {
326 $mask &= ~($catmask | $DeadBits{$word} | $All);
329 { Croaker("Unknown warnings category '$word'")}
332 ${^WARNING_BITS} = $mask ;
335 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
337 sub MESSAGE () { 4 };
347 my $has_message = $wanted & MESSAGE;
349 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
350 my $sub = (caller 1)[3];
351 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
352 Croaker("Usage: $sub($syntax)");
355 my $message = pop if $has_message;
358 # check the category supplied.
360 if (my $type = ref $category) {
361 Croaker("not an object")
362 if exists $builtin_type{$type};
366 $offset = $Offsets{$category};
367 Croaker("Unknown warnings category '$category'")
368 unless defined $offset;
371 $category = (caller(1))[0] ;
372 $offset = $Offsets{$category};
373 Croaker("package '$category' not registered for warnings")
374 unless defined $offset ;
382 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
383 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
388 $i = _error_loc(); # see where Carp will allocate the error
391 # Default to 0 if caller returns nothing. Default to $DEFAULT if it
392 # explicitly returns undef.
393 my(@callers_bitmask) = (caller($i))[9] ;
394 my $callers_bitmask =
395 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
398 foreach my $type (FATAL, NORMAL) {
399 next unless $wanted & $type;
401 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
402 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
405 # &enabled and &fatal_enabled
406 return $results[0] unless $has_message;
408 # &warnif, and the category is neither enabled as warning nor as fatal
409 return if $wanted == (NORMAL | FATAL | MESSAGE)
410 && !($results[0] || $results[1]);
413 Carp::croak($message) if $results[0];
414 # will always get here for &warn. will only get here for &warnif if the
415 # category is enabled
416 Carp::carp($message);
424 vec($mask, $bit, 1) = 1;
428 sub register_categories
432 for my $name (@names) {
433 if (! defined $Bits{$name}) {
434 $Bits{$name} = _mkMask($LAST_BIT);
435 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
436 $Offsets{$name} = $LAST_BIT ++;
437 foreach my $k (keys %Bits) {
438 vec($Bits{$k}, $LAST_BIT, 1) = 0;
440 $DeadBits{$name} = _mkMask($LAST_BIT);
441 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
448 goto &Carp::short_error_loc; # don't introduce another stack frame
453 return __chk(NORMAL, @_);
458 return __chk(FATAL, @_);
463 return __chk(FATAL | MESSAGE, @_);
468 return __chk(NORMAL | FATAL | MESSAGE, @_);
471 # These are not part of any public interface, so we can delete them to save
473 delete @warnings::{qw(NORMAL FATAL MESSAGE)};
479 warnings - Perl pragma to control optional warnings
489 use warnings::register;
490 if (warnings::enabled()) {
491 warnings::warn("some warning");
494 if (warnings::enabled("void")) {
495 warnings::warn("void", "some warning");
498 if (warnings::enabled($object)) {
499 warnings::warn($object, "some warning");
502 warnings::warnif("some warning");
503 warnings::warnif("void", "some warning");
504 warnings::warnif($object, "some warning");
508 The C<warnings> pragma gives control over which warnings are enabled in
509 which parts of a Perl program. It's a more flexible alternative for
510 both the command line flag B<-w> and the equivalent Perl variable,
513 This pragma works just like the C<strict> pragma.
514 This means that the scope of the warning pragma is limited to the
515 enclosing block. It also means that the pragma setting will not
516 leak across files (via C<use>, C<require> or C<do>). This allows
517 authors to independently define the degree of warning checks that will
518 be applied to their module.
520 By default, optional warnings are disabled, so any legacy code that
521 doesn't attempt to control the warnings will work unchanged.
523 All warnings are enabled in a block by either of these:
528 Similarly all warnings are disabled in a block by either of these:
533 For example, consider the code below:
543 The code in the enclosing block has warnings enabled, but the inner
544 block has them disabled. In this case that means the assignment to the
545 scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
546 warning, but the assignment to the scalar C<$b> will not.
548 =head2 Default Warnings and Optional Warnings
550 Before the introduction of lexical warnings, Perl had two classes of
551 warnings: mandatory and optional.
553 As its name suggests, if your code tripped a mandatory warning, you
554 would get a warning whether you wanted it or not.
555 For example, the code below would always produce an C<"isn't numeric">
556 warning about the "2:".
560 With the introduction of lexical warnings, mandatory warnings now become
561 I<default> warnings. The difference is that although the previously
562 mandatory warnings are still enabled by default, they can then be
563 subsequently enabled or disabled with the lexical warning pragma. For
564 example, in the code below, an C<"isn't numeric"> warning will only
565 be reported for the C<$a> variable.
571 Note that neither the B<-w> flag or the C<$^W> can be used to
572 disable/enable default warnings. They are still mandatory in this case.
574 =head2 What's wrong with B<-w> and C<$^W>
576 Although very useful, the big problem with using B<-w> on the command
577 line to enable warnings is that it is all or nothing. Take the typical
578 scenario when you are writing a Perl program. Parts of the code you
579 will write yourself, but it's very likely that you will make use of
580 pre-written Perl modules. If you use the B<-w> flag in this case, you
581 end up enabling warnings in pieces of code that you haven't written.
583 Similarly, using C<$^W> to either disable or enable blocks of code is
584 fundamentally flawed. For a start, say you want to disable warnings in
585 a block of code. You might expect this to be enough to do the trick:
593 When this code is run with the B<-w> flag, a warning will be produced
594 for the C<$a> line: C<"Reversed += operator">.
596 The problem is that Perl has both compile-time and run-time warnings. To
597 disable compile-time warnings you need to rewrite the code like this:
605 The other big problem with C<$^W> is the way you can inadvertently
606 change the warning setting in unexpected places in your code. For example,
607 when the code below is run (without the B<-w> flag), the second call
608 to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
623 This is a side-effect of C<$^W> being dynamically scoped.
625 Lexical warnings get around these limitations by allowing finer control
626 over where warnings can or can't be tripped.
628 =head2 Controlling Warnings from the Command Line
630 There are three Command Line flags that can be used to control when
631 warnings are (or aren't) produced:
638 This is the existing flag. If the lexical warnings pragma is B<not>
639 used in any of you code, or any of the modules that you use, this flag
640 will enable warnings everywhere. See L<Backward Compatibility> for
641 details of how this flag interacts with lexical warnings.
646 If the B<-W> flag is used on the command line, it will enable all warnings
647 throughout the program regardless of whether warnings were disabled
648 locally using C<no warnings> or C<$^W =0>.
649 This includes all files that get
650 included via C<use>, C<require> or C<do>.
651 Think of it as the Perl equivalent of the "lint" command.
656 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
660 =head2 Backward Compatibility
662 If you are used to working with a version of Perl prior to the
663 introduction of lexically scoped warnings, or have code that uses both
664 lexical warnings and C<$^W>, this section will describe how they interact.
666 How Lexical Warnings interact with B<-w>/C<$^W>:
672 If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
673 control warnings is used and neither C<$^W> nor the C<warnings> pragma
674 are used, then default warnings will be enabled and optional warnings
676 This means that legacy code that doesn't attempt to control the warnings
681 The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
682 means that any legacy code that currently relies on manipulating C<$^W>
683 to control warning behavior will still work as is.
687 Apart from now being a boolean, the C<$^W> variable operates in exactly
688 the same horrible uncontrolled global way, except that it cannot
689 disable/enable default warnings.
693 If a piece of code is under the control of the C<warnings> pragma,
694 both the C<$^W> variable and the B<-w> flag will be ignored for the
695 scope of the lexical warning.
699 The only way to override a lexical warnings setting is with the B<-W>
700 or B<-X> command line flags.
704 The combined effect of 3 & 4 is that it will allow code which uses
705 the C<warnings> pragma to control the warning behavior of $^W-type
706 code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
708 =head2 Category Hierarchy
709 X<warning, categories>
711 A hierarchy of "categories" have been defined to allow groups of warnings
712 to be enabled/disabled in isolation.
714 The current hierarchy is:
726 | +- experimental::autoderef
728 | +- experimental::lexical_subs
730 | +- experimental::lexical_topic
732 | +- experimental::postderef
734 | +- experimental::refaliasing
736 | +- experimental::regex_sets
738 | +- experimental::signatures
740 | +- experimental::smartmatch
742 | +- experimental::win32_perlio
846 Just like the "strict" pragma any of these categories can be combined
848 use warnings qw(void redefine);
849 no warnings qw(io syntax untie);
851 Also like the "strict" pragma, if there is more than one instance of the
852 C<warnings> pragma in a given scope the cumulative effect is additive.
854 use warnings qw(void); # only "void" warnings enabled
856 use warnings qw(io); # only "void" & "io" warnings enabled
858 no warnings qw(void); # only "io" warnings enabled
860 To determine which category a specific warning has been assigned to see
863 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
864 sub-category of the "syntax" category. It is now a top-level category
867 Note: Before 5.21.0, the "missing" lexical warnings category was
868 internally defined to be the same as the "uninitialized" category. It
869 is now a top-level category in its own right.
871 =head2 Fatal Warnings
874 The presence of the word "FATAL" in the category list will escalate any
875 warnings detected from the categories specified in the lexical scope
876 into fatal errors. In the code below, the use of C<time>, C<length>
877 and C<join> can all produce a C<"Useless use of xxx in void context">
885 use warnings FATAL => qw(void);
893 When run it produces this output
895 Useless use of time in void context at fatal line 3.
896 Useless use of length in void context at fatal line 7.
898 The scope where C<length> is used has escalated the C<void> warnings
899 category into a fatal error, so the program terminates immediately when it
900 encounters the warning.
902 To explicitly turn off a "FATAL" warning you just disable the warning
903 it is associated with. So, for example, to disable the "void" warning
904 in the example above, either of these will do the trick:
906 no warnings qw(void);
907 no warnings FATAL => qw(void);
909 If you want to downgrade a warning that has been escalated into a fatal
910 error back to a normal warning, you can use the "NONFATAL" keyword. For
911 example, the code below will promote all warnings into fatal errors,
912 except for those in the "syntax" category.
914 use warnings FATAL => 'all', NONFATAL => 'syntax';
916 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
919 use v5.20; # Perl 5.20 or greater is required for the following
920 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
922 If you want your program to be compatible with versions of Perl before
923 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
924 previous versions of Perl, the behavior of the statements
925 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
926 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
927 they included the C<< => 'all' >> portion. As of 5.20, they do.)
929 B<NOTE:> Users of FATAL warnings, especially
930 those using C<< FATAL => 'all' >>
931 should be fully aware that they are risking future portability of their
932 programs by doing so. Perl makes absolutely no commitments to not
933 introduce new warnings, or warnings categories in the future, and indeed
934 we explicitly reserve the right to do so. Code that may not warn now may
935 warn in a future release of Perl if the Perl5 development team deems it
936 in the best interests of the community to do so. Should code using FATAL
937 warnings break due to the introduction of a new warning we will NOT
938 consider it an incompatible change. Users of FATAL warnings should take
939 special caution during upgrades to check to see if their code triggers
940 any new warnings and should pay particular attention to the fine print of
941 the documentation of the features they use to ensure they do not exploit
942 features that are documented as risky, deprecated, or unspecified, or where
943 the documentation says "so don't do that", or anything with the same sense
944 and spirit. Use of such features in combination with FATAL warnings is
945 ENTIRELY AT THE USER'S RISK.
947 =head2 Reporting Warnings from a Module
948 X<warning, reporting> X<warning, registering>
950 The C<warnings> pragma provides a number of functions that are useful for
951 module authors. These are used when you want to report a module-specific
952 warning to a calling module has enabled warnings via the C<warnings>
955 Consider the module C<MyMod::Abc> below.
959 use warnings::register;
963 if ($path !~ m#^/#) {
964 warnings::warn("changing relative path to /var/abc")
965 if warnings::enabled();
966 $path = "/var/abc/$path";
972 The call to C<warnings::register> will create a new warnings category
973 called "MyMod::Abc", i.e. the new category name matches the current
974 package name. The C<open> function in the module will display a warning
975 message if it gets given a relative path as a parameter. This warnings
976 will only be displayed if the code that uses C<MyMod::Abc> has actually
977 enabled them with the C<warnings> pragma like below.
980 use warnings 'MyMod::Abc';
982 abc::open("../fred.txt");
984 It is also possible to test whether the pre-defined warnings categories are
985 set in the calling module with the C<warnings::enabled> function. Consider
986 this snippet of code:
991 warnings::warnif("deprecated",
992 "open is deprecated, use new instead");
1000 The function C<open> has been deprecated, so code has been included to
1001 display a warning message whenever the calling module has (at least) the
1002 "deprecated" warnings category enabled. Something like this, say.
1004 use warnings 'deprecated';
1007 MyMod::Abc::open($filename);
1009 Either the C<warnings::warn> or C<warnings::warnif> function should be
1010 used to actually display the warnings message. This is because they can
1011 make use of the feature that allows warnings to be escalated into fatal
1012 errors. So in this case
1015 use warnings FATAL => 'MyMod::Abc';
1017 MyMod::Abc::open('../fred.txt');
1019 the C<warnings::warnif> function will detect this and die after
1020 displaying the warning message.
1022 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
1023 and C<warnings::enabled> can optionally take an object reference in place
1024 of a category name. In this case the functions will use the class name
1025 of the object as the warnings category.
1027 Consider this example:
1032 use warnings::register;
1045 if ($value % 2 && warnings::enabled($self))
1046 { warnings::warn($self, "Odd numbers are unsafe") }
1053 $self->check($value);
1061 use warnings::register;
1063 our @ISA = qw( Original );
1073 The code below makes use of both modules, but it only enables warnings from
1078 use warnings 'Derived';
1079 my $a = Original->new();
1081 my $b = Derived->new();
1084 When this code is run only the C<Derived> object, C<$b>, will generate
1087 Odd numbers are unsafe at main.pl line 7
1089 Notice also that the warning is reported at the line where the object is first
1092 When registering new categories of warning, you can supply more names to
1093 warnings::register like this:
1096 use warnings::register qw(format precision);
1100 warnings::warnif('MyModule::format', '...');
1106 =item use warnings::register
1108 Creates a new warnings category with the same name as the package where
1109 the call to the pragma is used.
1111 =item warnings::enabled()
1113 Use the warnings category with the same name as the current package.
1115 Return TRUE if that warnings category is enabled in the calling module.
1116 Otherwise returns FALSE.
1118 =item warnings::enabled($category)
1120 Return TRUE if the warnings category, C<$category>, is enabled in the
1122 Otherwise returns FALSE.
1124 =item warnings::enabled($object)
1126 Use the name of the class for the object reference, C<$object>, as the
1129 Return TRUE if that warnings category is enabled in the first scope
1130 where the object is used.
1131 Otherwise returns FALSE.
1133 =item warnings::fatal_enabled()
1135 Return TRUE if the warnings category with the same name as the current
1136 package has been set to FATAL in the calling module.
1137 Otherwise returns FALSE.
1139 =item warnings::fatal_enabled($category)
1141 Return TRUE if the warnings category C<$category> has been set to FATAL in
1143 Otherwise returns FALSE.
1145 =item warnings::fatal_enabled($object)
1147 Use the name of the class for the object reference, C<$object>, as the
1150 Return TRUE if that warnings category has been set to FATAL in the first
1151 scope where the object is used.
1152 Otherwise returns FALSE.
1154 =item warnings::warn($message)
1156 Print C<$message> to STDERR.
1158 Use the warnings category with the same name as the current package.
1160 If that warnings category has been set to "FATAL" in the calling module
1161 then die. Otherwise return.
1163 =item warnings::warn($category, $message)
1165 Print C<$message> to STDERR.
1167 If the warnings category, C<$category>, has been set to "FATAL" in the
1168 calling module then die. Otherwise return.
1170 =item warnings::warn($object, $message)
1172 Print C<$message> to STDERR.
1174 Use the name of the class for the object reference, C<$object>, as the
1177 If that warnings category has been set to "FATAL" in the scope where C<$object>
1178 is first used then die. Otherwise return.
1181 =item warnings::warnif($message)
1185 if (warnings::enabled())
1186 { warnings::warn($message) }
1188 =item warnings::warnif($category, $message)
1192 if (warnings::enabled($category))
1193 { warnings::warn($category, $message) }
1195 =item warnings::warnif($object, $message)
1199 if (warnings::enabled($object))
1200 { warnings::warn($object, $message) }
1202 =item warnings::register_categories(@names)
1204 This registers warning categories for the given names and is primarily for
1205 use by the warnings::register pragma.
1209 See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.