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");
18 # Warnings Categories added in Perl 5.008
60 'uninitialized' => 82,
66 # Warnings Categories added in Perl 5.011
70 # Warnings Categories added in Perl 5.013
75 # Warnings Categories added in Perl 5.017
76 'experimental' => 102,
77 'experimental::lexical_subs' => 104,
78 'experimental::lexical_topic' => 106,
79 'experimental::regex_sets' => 108,
80 'experimental::smartmatch' => 110,
82 # Warnings Categories added in Perl 5.019
83 'experimental::autoderef' => 112,
84 'experimental::postderef' => 114,
85 'experimental::signatures' => 116,
88 # Warnings Categories added in Perl 5.021
89 'experimental::bitwise' => 120,
90 'experimental::const_attr' => 122,
91 'experimental::re_strict' => 124,
92 'experimental::refaliasing' => 126,
93 'experimental::win32_perlio' => 128,
100 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..67]
101 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
102 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
103 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
104 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
105 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
106 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
107 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
108 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
109 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
110 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x15\x55\x01", # [51..58,60..64]
111 'experimental::autoderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [56]
112 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [60]
113 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [61]
114 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [52]
115 'experimental::lexical_topic' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [53]
116 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [57]
117 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [62]
118 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [63]
119 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [54]
120 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [58]
121 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [55]
122 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [64]
123 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
124 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [47]
125 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [46]
126 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
127 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
128 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [5..11,59]
129 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
130 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [65]
131 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
132 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
133 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [66]
134 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
135 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [48]
136 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [49]
137 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
138 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
139 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
140 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
141 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
142 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
143 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
144 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
145 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
146 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
147 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [36]
148 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
149 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
150 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [67]
151 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
152 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [37]
153 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [38]
154 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
155 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
156 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
157 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [50]
158 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00", # [28..38,47]
159 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [59]
160 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [39]
161 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [40]
162 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [41]
163 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
164 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [42]
165 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [43]
166 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00\x00", # [44,48..50]
167 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [45]
171 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..67]
172 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
173 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
174 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
175 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
176 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
177 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
178 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
179 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
180 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
181 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\x2a\xaa\x02", # [51..58,60..64]
182 'experimental::autoderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [56]
183 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [60]
184 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [61]
185 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [52]
186 'experimental::lexical_topic' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [53]
187 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [57]
188 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [62]
189 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [63]
190 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [54]
191 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [58]
192 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [55]
193 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [64]
194 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
195 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [47]
196 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [46]
197 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
198 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
199 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [5..11,59]
200 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
201 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [65]
202 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
203 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
204 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [66]
205 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
206 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [48]
207 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [49]
208 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
209 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
210 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
211 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
212 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
213 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
214 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
215 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
216 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
217 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
218 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [36]
219 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
220 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
221 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [67]
222 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
223 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [37]
224 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [38]
225 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
226 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
227 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
228 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [50]
229 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00", # [28..38,47]
230 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [59]
231 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [39]
232 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [40]
233 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [41]
234 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
235 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [42]
236 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [43]
237 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00\x00", # [44,48..50]
238 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [45]
241 # These are used by various things, including our own tests
242 our $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
243 our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x15\x55\x05", # [2,56,60,61,52,53,57,62,63,54,58,55,64,4,65,22,23,25]
244 our $LAST_BIT = 136 ;
247 our $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
251 require Carp; # this initializes %CarpInternal
252 local $Carp::CarpInternal{'warnings'};
253 delete $Carp::CarpInternal{'warnings'};
263 foreach my $word ( @_ ) {
264 if ($word eq 'FATAL') {
268 elsif ($word eq 'NONFATAL') {
272 elsif ($catmask = $Bits{$word}) {
274 $mask |= $DeadBits{$word} if $fatal ;
275 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
278 { Croaker("Unknown warnings category '$word'")}
286 # called from B::Deparse.pm
287 push @_, 'all' unless @_ ;
288 return _bits(undef, @_) ;
295 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
297 if (vec($mask, $Offsets{'all'}, 1)) {
298 $mask |= $Bits{'all'} ;
299 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
302 # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
303 push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
305 # Empty @_ is equivalent to @_ = 'all' ;
306 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
314 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
316 if (vec($mask, $Offsets{'all'}, 1)) {
317 $mask |= $Bits{'all'} ;
318 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
321 # append 'all' when implied (empty import list or after a lone "FATAL")
322 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
324 foreach my $word ( @_ ) {
325 if ($word eq 'FATAL') {
328 elsif ($catmask = $Bits{$word}) {
329 $mask &= ~($catmask | $DeadBits{$word} | $All);
332 { Croaker("Unknown warnings category '$word'")}
335 ${^WARNING_BITS} = $mask ;
338 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
340 sub MESSAGE () { 4 };
350 my $has_message = $wanted & MESSAGE;
352 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
353 my $sub = (caller 1)[3];
354 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
355 Croaker("Usage: $sub($syntax)");
358 my $message = pop if $has_message;
361 # check the category supplied.
363 if (my $type = ref $category) {
364 Croaker("not an object")
365 if exists $builtin_type{$type};
369 $offset = $Offsets{$category};
370 Croaker("Unknown warnings category '$category'")
371 unless defined $offset;
374 $category = (caller(1))[0] ;
375 $offset = $Offsets{$category};
376 Croaker("package '$category' not registered for warnings")
377 unless defined $offset ;
385 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
386 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
391 $i = _error_loc(); # see where Carp will allocate the error
394 # Default to 0 if caller returns nothing. Default to $DEFAULT if it
395 # explicitly returns undef.
396 my(@callers_bitmask) = (caller($i))[9] ;
397 my $callers_bitmask =
398 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
401 foreach my $type (FATAL, NORMAL) {
402 next unless $wanted & $type;
404 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
405 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
408 # &enabled and &fatal_enabled
409 return $results[0] unless $has_message;
411 # &warnif, and the category is neither enabled as warning nor as fatal
412 return if $wanted == (NORMAL | FATAL | MESSAGE)
413 && !($results[0] || $results[1]);
416 Carp::croak($message) if $results[0];
417 # will always get here for &warn. will only get here for &warnif if the
418 # category is enabled
419 Carp::carp($message);
427 vec($mask, $bit, 1) = 1;
431 sub register_categories
435 for my $name (@names) {
436 if (! defined $Bits{$name}) {
437 $Bits{$name} = _mkMask($LAST_BIT);
438 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
439 $Offsets{$name} = $LAST_BIT ++;
440 foreach my $k (keys %Bits) {
441 vec($Bits{$k}, $LAST_BIT, 1) = 0;
443 $DeadBits{$name} = _mkMask($LAST_BIT);
444 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
451 goto &Carp::short_error_loc; # don't introduce another stack frame
456 return __chk(NORMAL, @_);
461 return __chk(FATAL, @_);
466 return __chk(FATAL | MESSAGE, @_);
471 return __chk(NORMAL | FATAL | MESSAGE, @_);
474 # These are not part of any public interface, so we can delete them to save
476 delete @warnings::{qw(NORMAL FATAL MESSAGE)};
482 warnings - Perl pragma to control optional warnings
492 use warnings::register;
493 if (warnings::enabled()) {
494 warnings::warn("some warning");
497 if (warnings::enabled("void")) {
498 warnings::warn("void", "some warning");
501 if (warnings::enabled($object)) {
502 warnings::warn($object, "some warning");
505 warnings::warnif("some warning");
506 warnings::warnif("void", "some warning");
507 warnings::warnif($object, "some warning");
511 The C<warnings> pragma gives control over which warnings are enabled in
512 which parts of a Perl program. It's a more flexible alternative for
513 both the command line flag B<-w> and the equivalent Perl variable,
516 This pragma works just like the C<strict> pragma.
517 This means that the scope of the warning pragma is limited to the
518 enclosing block. It also means that the pragma setting will not
519 leak across files (via C<use>, C<require> or C<do>). This allows
520 authors to independently define the degree of warning checks that will
521 be applied to their module.
523 By default, optional warnings are disabled, so any legacy code that
524 doesn't attempt to control the warnings will work unchanged.
526 All warnings are enabled in a block by either of these:
531 Similarly all warnings are disabled in a block by either of these:
536 For example, consider the code below:
546 The code in the enclosing block has warnings enabled, but the inner
547 block has them disabled. In this case that means the assignment to the
548 scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
549 warning, but the assignment to the scalar C<$b> will not.
551 =head2 Default Warnings and Optional Warnings
553 Before the introduction of lexical warnings, Perl had two classes of
554 warnings: mandatory and optional.
556 As its name suggests, if your code tripped a mandatory warning, you
557 would get a warning whether you wanted it or not.
558 For example, the code below would always produce an C<"isn't numeric">
559 warning about the "2:".
563 With the introduction of lexical warnings, mandatory warnings now become
564 I<default> warnings. The difference is that although the previously
565 mandatory warnings are still enabled by default, they can then be
566 subsequently enabled or disabled with the lexical warning pragma. For
567 example, in the code below, an C<"isn't numeric"> warning will only
568 be reported for the C<$a> variable.
574 Note that neither the B<-w> flag or the C<$^W> can be used to
575 disable/enable default warnings. They are still mandatory in this case.
577 =head2 What's wrong with B<-w> and C<$^W>
579 Although very useful, the big problem with using B<-w> on the command
580 line to enable warnings is that it is all or nothing. Take the typical
581 scenario when you are writing a Perl program. Parts of the code you
582 will write yourself, but it's very likely that you will make use of
583 pre-written Perl modules. If you use the B<-w> flag in this case, you
584 end up enabling warnings in pieces of code that you haven't written.
586 Similarly, using C<$^W> to either disable or enable blocks of code is
587 fundamentally flawed. For a start, say you want to disable warnings in
588 a block of code. You might expect this to be enough to do the trick:
596 When this code is run with the B<-w> flag, a warning will be produced
597 for the C<$a> line: C<"Reversed += operator">.
599 The problem is that Perl has both compile-time and run-time warnings. To
600 disable compile-time warnings you need to rewrite the code like this:
608 The other big problem with C<$^W> is the way you can inadvertently
609 change the warning setting in unexpected places in your code. For example,
610 when the code below is run (without the B<-w> flag), the second call
611 to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
626 This is a side-effect of C<$^W> being dynamically scoped.
628 Lexical warnings get around these limitations by allowing finer control
629 over where warnings can or can't be tripped.
631 =head2 Controlling Warnings from the Command Line
633 There are three Command Line flags that can be used to control when
634 warnings are (or aren't) produced:
641 This is the existing flag. If the lexical warnings pragma is B<not>
642 used in any of you code, or any of the modules that you use, this flag
643 will enable warnings everywhere. See L<Backward Compatibility> for
644 details of how this flag interacts with lexical warnings.
649 If the B<-W> flag is used on the command line, it will enable all warnings
650 throughout the program regardless of whether warnings were disabled
651 locally using C<no warnings> or C<$^W =0>.
652 This includes all files that get
653 included via C<use>, C<require> or C<do>.
654 Think of it as the Perl equivalent of the "lint" command.
659 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
663 =head2 Backward Compatibility
665 If you are used to working with a version of Perl prior to the
666 introduction of lexically scoped warnings, or have code that uses both
667 lexical warnings and C<$^W>, this section will describe how they interact.
669 How Lexical Warnings interact with B<-w>/C<$^W>:
675 If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
676 control warnings is used and neither C<$^W> nor the C<warnings> pragma
677 are used, then default warnings will be enabled and optional warnings
679 This means that legacy code that doesn't attempt to control the warnings
684 The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
685 means that any legacy code that currently relies on manipulating C<$^W>
686 to control warning behavior will still work as is.
690 Apart from now being a boolean, the C<$^W> variable operates in exactly
691 the same horrible uncontrolled global way, except that it cannot
692 disable/enable default warnings.
696 If a piece of code is under the control of the C<warnings> pragma,
697 both the C<$^W> variable and the B<-w> flag will be ignored for the
698 scope of the lexical warning.
702 The only way to override a lexical warnings setting is with the B<-W>
703 or B<-X> command line flags.
707 The combined effect of 3 & 4 is that it will allow code which uses
708 the C<warnings> pragma to control the warning behavior of $^W-type
709 code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
711 =head2 Category Hierarchy
712 X<warning, categories>
714 A hierarchy of "categories" have been defined to allow groups of warnings
715 to be enabled/disabled in isolation.
717 The current hierarchy is:
729 | +- experimental::autoderef
731 | +- experimental::bitwise
733 | +- experimental::const_attr
735 | +- experimental::lexical_subs
737 | +- experimental::lexical_topic
739 | +- experimental::postderef
741 | +- experimental::re_strict
743 | +- experimental::refaliasing
745 | +- experimental::regex_sets
747 | +- experimental::signatures
749 | +- experimental::smartmatch
751 | +- experimental::win32_perlio
855 Just like the "strict" pragma any of these categories can be combined
857 use warnings qw(void redefine);
858 no warnings qw(io syntax untie);
860 Also like the "strict" pragma, if there is more than one instance of the
861 C<warnings> pragma in a given scope the cumulative effect is additive.
863 use warnings qw(void); # only "void" warnings enabled
865 use warnings qw(io); # only "void" & "io" warnings enabled
867 no warnings qw(void); # only "io" warnings enabled
869 To determine which category a specific warning has been assigned to see
872 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
873 sub-category of the "syntax" category. It is now a top-level category
876 Note: Before 5.21.0, the "missing" lexical warnings category was
877 internally defined to be the same as the "uninitialized" category. It
878 is now a top-level category in its own right.
880 =head2 Fatal Warnings
883 The presence of the word "FATAL" in the category list will escalate any
884 warnings detected from the categories specified in the lexical scope
885 into fatal errors. In the code below, the use of C<time>, C<length>
886 and C<join> can all produce a C<"Useless use of xxx in void context">
894 use warnings FATAL => qw(void);
902 When run it produces this output
904 Useless use of time in void context at fatal line 3.
905 Useless use of length in void context at fatal line 7.
907 The scope where C<length> is used has escalated the C<void> warnings
908 category into a fatal error, so the program terminates immediately when it
909 encounters the warning.
911 To explicitly turn off a "FATAL" warning you just disable the warning
912 it is associated with. So, for example, to disable the "void" warning
913 in the example above, either of these will do the trick:
915 no warnings qw(void);
916 no warnings FATAL => qw(void);
918 If you want to downgrade a warning that has been escalated into a fatal
919 error back to a normal warning, you can use the "NONFATAL" keyword. For
920 example, the code below will promote all warnings into fatal errors,
921 except for those in the "syntax" category.
923 use warnings FATAL => 'all', NONFATAL => 'syntax';
925 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
928 use v5.20; # Perl 5.20 or greater is required for the following
929 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
931 If you want your program to be compatible with versions of Perl before
932 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
933 previous versions of Perl, the behavior of the statements
934 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
935 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
936 they included the C<< => 'all' >> portion. As of 5.20, they do.)
938 B<NOTE:> Users of FATAL warnings, especially
939 those using C<< FATAL => 'all' >>
940 should be fully aware that they are risking future portability of their
941 programs by doing so. Perl makes absolutely no commitments to not
942 introduce new warnings, or warnings categories in the future, and indeed
943 we explicitly reserve the right to do so. Code that may not warn now may
944 warn in a future release of Perl if the Perl5 development team deems it
945 in the best interests of the community to do so. Should code using FATAL
946 warnings break due to the introduction of a new warning we will NOT
947 consider it an incompatible change. Users of FATAL warnings should take
948 special caution during upgrades to check to see if their code triggers
949 any new warnings and should pay particular attention to the fine print of
950 the documentation of the features they use to ensure they do not exploit
951 features that are documented as risky, deprecated, or unspecified, or where
952 the documentation says "so don't do that", or anything with the same sense
953 and spirit. Use of such features in combination with FATAL warnings is
954 ENTIRELY AT THE USER'S RISK.
956 =head2 Reporting Warnings from a Module
957 X<warning, reporting> X<warning, registering>
959 The C<warnings> pragma provides a number of functions that are useful for
960 module authors. These are used when you want to report a module-specific
961 warning to a calling module has enabled warnings via the C<warnings>
964 Consider the module C<MyMod::Abc> below.
968 use warnings::register;
972 if ($path !~ m#^/#) {
973 warnings::warn("changing relative path to /var/abc")
974 if warnings::enabled();
975 $path = "/var/abc/$path";
981 The call to C<warnings::register> will create a new warnings category
982 called "MyMod::Abc", i.e. the new category name matches the current
983 package name. The C<open> function in the module will display a warning
984 message if it gets given a relative path as a parameter. This warnings
985 will only be displayed if the code that uses C<MyMod::Abc> has actually
986 enabled them with the C<warnings> pragma like below.
989 use warnings 'MyMod::Abc';
991 abc::open("../fred.txt");
993 It is also possible to test whether the pre-defined warnings categories are
994 set in the calling module with the C<warnings::enabled> function. Consider
995 this snippet of code:
1000 warnings::warnif("deprecated",
1001 "open is deprecated, use new instead");
1009 The function C<open> has been deprecated, so code has been included to
1010 display a warning message whenever the calling module has (at least) the
1011 "deprecated" warnings category enabled. Something like this, say.
1013 use warnings 'deprecated';
1016 MyMod::Abc::open($filename);
1018 Either the C<warnings::warn> or C<warnings::warnif> function should be
1019 used to actually display the warnings message. This is because they can
1020 make use of the feature that allows warnings to be escalated into fatal
1021 errors. So in this case
1024 use warnings FATAL => 'MyMod::Abc';
1026 MyMod::Abc::open('../fred.txt');
1028 the C<warnings::warnif> function will detect this and die after
1029 displaying the warning message.
1031 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
1032 and C<warnings::enabled> can optionally take an object reference in place
1033 of a category name. In this case the functions will use the class name
1034 of the object as the warnings category.
1036 Consider this example:
1041 use warnings::register;
1054 if ($value % 2 && warnings::enabled($self))
1055 { warnings::warn($self, "Odd numbers are unsafe") }
1062 $self->check($value);
1070 use warnings::register;
1072 our @ISA = qw( Original );
1082 The code below makes use of both modules, but it only enables warnings from
1087 use warnings 'Derived';
1088 my $a = Original->new();
1090 my $b = Derived->new();
1093 When this code is run only the C<Derived> object, C<$b>, will generate
1096 Odd numbers are unsafe at main.pl line 7
1098 Notice also that the warning is reported at the line where the object is first
1101 When registering new categories of warning, you can supply more names to
1102 warnings::register like this:
1105 use warnings::register qw(format precision);
1109 warnings::warnif('MyModule::format', '...');
1115 =item use warnings::register
1117 Creates a new warnings category with the same name as the package where
1118 the call to the pragma is used.
1120 =item warnings::enabled()
1122 Use the warnings category with the same name as the current package.
1124 Return TRUE if that warnings category is enabled in the calling module.
1125 Otherwise returns FALSE.
1127 =item warnings::enabled($category)
1129 Return TRUE if the warnings category, C<$category>, is enabled in the
1131 Otherwise returns FALSE.
1133 =item warnings::enabled($object)
1135 Use the name of the class for the object reference, C<$object>, as the
1138 Return TRUE if that warnings category is enabled in the first scope
1139 where the object is used.
1140 Otherwise returns FALSE.
1142 =item warnings::fatal_enabled()
1144 Return TRUE if the warnings category with the same name as the current
1145 package has been set to FATAL in the calling module.
1146 Otherwise returns FALSE.
1148 =item warnings::fatal_enabled($category)
1150 Return TRUE if the warnings category C<$category> has been set to FATAL in
1152 Otherwise returns FALSE.
1154 =item warnings::fatal_enabled($object)
1156 Use the name of the class for the object reference, C<$object>, as the
1159 Return TRUE if that warnings category has been set to FATAL in the first
1160 scope where the object is used.
1161 Otherwise returns FALSE.
1163 =item warnings::warn($message)
1165 Print C<$message> to STDERR.
1167 Use the warnings category with the same name as the current package.
1169 If that warnings category has been set to "FATAL" in the calling module
1170 then die. Otherwise return.
1172 =item warnings::warn($category, $message)
1174 Print C<$message> to STDERR.
1176 If the warnings category, C<$category>, has been set to "FATAL" in the
1177 calling module then die. Otherwise return.
1179 =item warnings::warn($object, $message)
1181 Print C<$message> to STDERR.
1183 Use the name of the class for the object reference, C<$object>, as the
1186 If that warnings category has been set to "FATAL" in the scope where C<$object>
1187 is first used then die. Otherwise return.
1190 =item warnings::warnif($message)
1194 if (warnings::enabled())
1195 { warnings::warn($message) }
1197 =item warnings::warnif($category, $message)
1201 if (warnings::enabled($category))
1202 { warnings::warn($category, $message) }
1204 =item warnings::warnif($object, $message)
1208 if (warnings::enabled($object))
1209 { warnings::warn($object, $message) }
1211 =item warnings::register_categories(@names)
1213 This registers warning categories for the given names and is primarily for
1214 use by the warnings::register pragma.
1218 See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.