3 $|=1; # outherwise things get mixed up in output
8 set_up_inc( qw '../lib ../ext/re' );
9 eval 'require Config'; # assume defaults if this fails
12 skip_all_without_unicode_tables();
15 use open qw(:utf8 :std);
17 # Kind of a kludge to mark warnings to be expected only if we are testing
18 # under "use re 'strict'"
19 my $only_strict_marker = ':expected_only_under_strict';
21 ## If the markers used are changed (search for "MARKER1" in regcomp.c),
22 ## update only these two regexs, and leave the {#} in the @death/@warning
23 ## arrays below. The {#} is a meta-marker -- it marks where the marker should
26 sub fixup_expect ($$) {
28 # Fixes up the expected results by inserting the boiler plate text.
29 # Returns empty string if that is what is expected. Otherwise, handles
30 # either a scalar, turning it into a single element array; or a ref to an
31 # array, adjusting each element. If called in array context, returns an
32 # array, otherwise the join of all elements.
34 # The string $only_strict_marker will be removed from any expect line it
35 # begins, and if $strict is not true, that expect line will be removed
36 # from the output (hence won't be expected)
38 my ($expect_ref, $strict) = @_;
39 return "" if $expect_ref eq "";
42 if (ref $expect_ref) {
43 @expect = @$expect_ref;
46 @expect = $expect_ref;
50 foreach my $element (@expect) {
51 $element =~ s/\{\#\}/in regex; marked by <-- HERE in/;
52 $element =~ s/\{\#\}/ <-- HERE /;
54 next if $element =~ s/ ^ $only_strict_marker \s* //x && ! $strict;
55 push @new_expect, $element;
57 return wantarray ? @new_expect : join "", @new_expect;
60 ## Because we don't "use utf8" in this file, we need to do some extra legwork
61 ## for the utf8 tests: Prepend 'use utf8' to the pattern, and mark the strings
62 ## to check against as UTF-8, but for this all to work properly, the character
63 ## 'ネ' (U+30CD) is required in each pattern somewhere as a marker.
65 ## This also creates a second variant of the tests to check if the
66 ## latin1 error messages are working correctly. Because we don't 'use utf8',
67 ## we can't tell if something is UTF-8 or Latin1, so you need the suffix
68 ## '; no latin1' to not have the second variant.
70 my $utf8 = "\x{30cd}";
75 for (my $i = 0; $i < @_; $i += 2) {
78 my $l1_pat = $pat =~ s/$utf8/$l1/gr;
80 $pat = "use utf8; $pat";
83 $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ];
84 @$msg = map { my $c = $_; utf8::decode($c); $c } @$msg;
87 $l1_msg = $msg =~ s/$utf8/$l1/gr;
90 push @ret, $pat => $msg;
92 push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/;
97 my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1;
98 my $inf_p1 = $inf_m1 + 2;
100 my $B_hex = sprintf("\\x%02X", ord "B");
101 my $low_mixed_alpha = ('A' lt 'a') ? 'A' : 'a';
102 my $high_mixed_alpha = ('A' lt 'a') ? 'a' : 'A';
103 my $low_mixed_digit = ('A' lt '0') ? 'A' : '0';
104 my $high_mixed_digit = ('A' lt '0') ? '0' : 'A';
106 my $colon_hex = sprintf "%02X", ord(":");
107 my $tab_hex = sprintf "%02X", ord("\t");
110 ## Key-value pairs of code/error of code that should have fatal errors.
114 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/',
116 '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/',
118 '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/',
120 '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/',
122 '/(?{ 1/' => 'Missing right curly or square bracket',
124 '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/',
125 '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/',
127 '/(?(1)/' => 'Switch (?(condition)... not terminated {#} m/(?(1){#}/',
128 '/(?(1)x/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x{#}/',
129 '/(?(1)x|y/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x|y{#}/',
130 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/',
132 '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/',
133 '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/',
134 '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/',
136 '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/',
138 '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/',
139 '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
140 '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/',
141 '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/',
142 '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/',
143 '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/',
144 '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/',
145 '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/',
146 '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/',
147 '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/',
148 '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
149 '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/',
150 '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/',
151 '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/',
152 '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/',
153 '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/',
154 '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/',
155 '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/',
156 '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/',
157 '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
159 '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
160 '/{(}/' => 'Unmatched ( {#} m/{({#}}/', # [perl #127599]
162 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",
165 '/x**/' => 'Nested quantifiers {#} m/x**{#}/',
167 '/x[/' => 'Unmatched [ {#} m/x[{#}/',
169 '/*/', => 'Quantifier follows nothing {#} m/*{#}/',
171 '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/',
173 '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/',
175 '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/',
177 '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
178 '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
180 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
182 '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/',
183 '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/',
185 '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/',
186 '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/',
188 '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/',
189 '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/',
191 '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/',
192 '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/',
194 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/',
196 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/',
198 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/',
200 '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/',
202 '/\p/' => 'Empty \p {#} m/\p{#}/',
203 '/\P/' => 'Empty \P {#} m/\P{#}/',
204 '/\p{}/' => 'Empty \p{} {#} m/\p{{#}}/',
205 '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/',
207 '/a\b{cde/' => 'Missing right brace on \b{} {#} m/a\b{{#}cde/',
208 '/a\B{cde/' => 'Missing right brace on \B{} {#} m/a\B{{#}cde/',
210 '/\b{}/' => 'Empty \b{} {#} m/\b{}{#}/',
211 '/\B{}/' => 'Empty \B{} {#} m/\B{}{#}/',
213 '/\b{gc}/' => "'gc' is an unknown bound type {#} m/\\b{gc{#}}/",
214 '/\B{gc}/' => "'gc' is an unknown bound type {#} m/\\B{gc{#}}/",
216 '/(?[[[::]]])/' => "Syntax error in (?[...]) in regex m/(?[[[::]]])/",
217 '/(?[[[:w:]]])/' => "Syntax error in (?[...]) in regex m/(?[[[:w:]]])/",
218 '/(?[[:w:]])/' => "",
219 '/[][[:alpha:]]' => "", # [perl #127581]
220 '/([.].*)[.]/' => "", # [perl #127582]
221 '/[.].*[.]/' => "", # [perl #127604]
222 '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/',
223 '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/',
224 '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/',
225 '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/',
226 '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/',
227 '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/',
228 '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/',
229 '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/',
230 '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/',
231 '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
232 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
233 '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/',
234 '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/',
235 '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/',
236 '/(?[ ( ) ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ ( ){#} ])/',
237 '/(?[[0]+()+])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[[0]+(){#}+])/',
238 '/(?[ \p{foo} ])/' => 'Can\'t find Unicode property definition "foo" {#} m/(?[ \p{foo}{#} ])/',
239 '/(?[ \p{ foo = bar } ])/' => 'Can\'t find Unicode property definition "foo = bar" {#} m/(?[ \p{ foo = bar }{#} ])/',
240 '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/',
241 '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/',
242 '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/',
243 '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/',
244 '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/',
245 '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/',
246 '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/',
247 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/',
248 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/',
249 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/',
250 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/',
251 'm/(?[[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/(?[[^\N{U+100.300{#}}]])/',
252 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/',
253 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/',
254 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/',
255 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
256 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/',
257 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/',
258 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
259 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/',
260 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
261 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/',
262 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/',
263 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/',
264 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/',
265 'm/(?&a/' => 'Sequence (?&... not terminated {#} m/(?&a{#}/',
266 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/',
267 "m/(?'/" => "Sequence (?'... not terminated {#} m/(?'{#}/",
268 "m/(?</" => "Sequence (?<... not terminated {#} m/(?<{#}/",
269 'm/(?&/' => 'Sequence (?&... not terminated {#} m/(?&{#}/',
270 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/',
271 "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/",
272 'm/\g{/' => 'Sequence \g{... not terminated {#} m/\g{{#}/',
273 'm/\k</' => 'Sequence \k<... not terminated {#} m/\k<{#}/',
274 'm/\cß/' => "Character following \"\\c\" must be printable ASCII",
275 '/((?# This is a comment in the middle of a token)?:foo)/' => 'In \'(?...)\', the \'(\' and \'?\' must be adjacent {#} m/((?# This is a comment in the middle of a token)?{#}:foo)/',
276 '/((?# This is a comment in the middle of a token)*FAIL)/' => 'In \'(*VERB...)\', the \'(\' and \'*\' must be adjacent {#} m/((?# This is a comment in the middle of a token)*{#}FAIL)/',
277 '/(?[\ &!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ &!{#}])/', # [perl #126180]
278 '/(?[\ +!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ +!{#}])/', # [perl #126180]
279 '/(?[\ -!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ -!{#}])/', # [perl #126180]
280 '/(?[\ ^!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ ^!{#}])/', # [perl #126180]
281 '/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/', # [perl #126180]
282 '/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/', # [perl #126204]
283 '/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/', # [perl #126404]
284 '/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
285 '/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
286 '/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
287 '/:{4,a}/' => 'Unescaped left brace in regex is illegal here {#} m/:{{#}4,a}/',
288 '/xa{3\,4}y/' => 'Unescaped left brace in regex is illegal here {#} m/xa{{#}3\,4}y/',
290 '/(?xmsixp:abc)/' => "",
291 '/(?xmsixp)abc/' => "",
292 '/(?xxxx:abc)/' => "",
293 '/(?<=/' => 'Sequence (?... not terminated {#} m/(?<={#}/', # [perl #128170]
297 # These are messages that are warnings when not strict; death under 'use re
298 # "strict". See comment before @warnings as to why some have a \x{100} in
299 # them. This array has 3 elements per construct. [0] is the regex to use;
300 # [1] is the message under no strict, and [2] is under strict.
301 my @death_only_under_strict = (
303 => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/',
305 => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/',
307 # XXX This is a confusing error message. The G isn't ignored; it just
308 # terminates the \x. Also some messages below are missing the <-- HERE,
309 # aren't all category 'regexp'. (Hence we have to turn off 'digit'
310 # messages as well below)
311 'm/\xAG/' => 'Illegal hexadecimal digit \'G\' ignored',
312 => 'Non-hex character {#} m/\xAG{#}/',
313 'm/[\xAG]/' => 'Illegal hexadecimal digit \'G\' ignored',
314 => 'Non-hex character {#} m/[\xAG{#}]/',
315 'm/\o{789}/' => 'Non-octal character \'8\'. Resolved as "\o{7}"',
316 => 'Non-octal character {#} m/\o{78{#}9}/',
317 'm/[\o{789}]/' => 'Non-octal character \'8\'. Resolved as "\o{7}"',
318 => 'Non-octal character {#} m/[\o{78{#}9}]/',
320 => 'Number with no digits {#} m/\x{}{#}/',
322 => 'Number with no digits {#} m/[\x{}{#}]/',
323 'm/\x{ABCDEFG}/' => 'Illegal hexadecimal digit \'G\' ignored',
324 => 'Non-hex character {#} m/\x{ABCDEFG{#}}/',
325 'm/[\x{ABCDEFG}]/' => 'Illegal hexadecimal digit \'G\' ignored',
326 => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/',
327 "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/',
328 => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/',
329 'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
330 => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
331 'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
332 => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
333 'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
334 => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
335 'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
336 => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
337 'm/[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[^\N{U+100.300}{#}]/',
338 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[^\N{U+100.300{#}}]/',
339 'm/[\x03-\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\x03-\N{U+100.300}{#}]/',
340 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/',
341 'm/[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}-\x{10FFFF}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\N{U+100.300}{#}-\x{10FFFF}]/',
342 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/',
343 '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/',
344 => 'Need exactly 3 octal digits {#} m/[\08{#}]/',
345 '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/',
346 => 'Need exactly 3 octal digits {#} m/[\018{#}]/',
348 => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/',
350 => 'Need exactly 3 octal digits {#} m/[\07]{#}/',
352 => 'Need exactly 3 octal digits {#} m/[\0005]{#}/',
353 '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/',
354 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/',
356 => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/',
357 '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
358 => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
359 '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
360 => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
361 '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
362 => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
363 '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
364 => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
365 '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
366 => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
367 '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
368 => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
369 '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
370 => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
371 '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
372 => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
373 '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/',
374 => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/',
377 # These need the character 'ネ' as a marker for mark_as_utf8()
378 my @death_utf8 = mark_as_utf8(
379 '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/',
381 '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/',
383 '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/',
385 '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/',
387 '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/',
389 '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/',
391 '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/',
393 '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/',
394 '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/',
395 '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/',
396 '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/',
397 '/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/',
398 '/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/',
399 '/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/',
401 '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/',
403 "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/",
406 '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/',
408 '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/',
410 '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/',
412 '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/',
414 '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/',
416 '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/',
418 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/',
420 '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/',
421 '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/',
422 '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/',
424 '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/',
427 '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/',
429 '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/',
431 '/ネ(?[[[:ネ]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ]]])ネ/",
432 '/ネ(?[[[:ネ: ])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ: ])ネ/",
433 '/ネ(?[[[::]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[::]]])ネ/",
434 '/ネ(?[[[:ネ:]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ:]]])ネ/",
435 '/ネ(?[[:ネ:]])ネ/' => "",
436 '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/',
437 '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/',
438 '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/',
439 '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/',
440 '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/',
441 '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/',
442 '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/',
443 '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/',
444 '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/',
445 '/(?[ \p{ネ} ])/' => 'Can\'t find Unicode property definition "ネ" {#} m/(?[ \p{ネ}{#} ])/',
446 '/(?[ \p{ ネ = bar } ])/' => 'Can\'t find Unicode property definition "ネ = bar" {#} m/(?[ \p{ ネ = bar }{#} ])/',
447 '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/',
448 '/(?[ \t + \e # ネ This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # ネ This was supposed to be a comment ])/',
449 'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>,
450 '/\cネ/' => "Character following \"\\c\" must be printable ASCII",
451 '/\b{ネ}/' => "'ネ' is an unknown bound type {#} m/\\b{ネ{#}}/",
452 '/\B{ネ}/' => "'ネ' is an unknown bound type {#} m/\\B{ネ{#}}/",
454 push @death, @death_utf8;
456 my @death_utf8_only_under_strict = (
457 "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/',
458 => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/',
459 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
460 => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
461 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
462 => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
463 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
464 => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
465 '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
466 => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
467 '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
468 => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
469 '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/',
470 => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/',
472 # Tests involving a user-defined charnames translator are in pat_advanced.t
474 # In the following arrays of warnings, the value can be an array of things to
475 # expect. If the empty string, it means no warning should be raised.
478 # Key-value pairs of code/error of code that should have non-fatal regexp
479 # warnings. Most currently have \x{100} appended to them to force them to be
480 # upgraded to UTF-8, and the first pass restarted. Previously this would
481 # cause some warnings to be output twice. This tests that that behavior has
485 'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
486 '/\b{g}/a' => "Using /u for '\\b{g}' instead of /a {#} m/\\b{g}{#}/",
487 '/\B{gcb}/a' => "Using /u for '\\B{gcb}' instead of /a {#} m/\\B{gcb}{#}/",
488 'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
489 'm/[[:cntrl:]][:^ascii:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/',
490 'm/[[:ascii]]\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/[[:ascii{#}]]\\x{100}/",
491 'm/(?[[:word]])\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/(?[[:word{#}]])\\x{100}/",
492 "m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
493 '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
494 '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',
495 '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/',
496 '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
497 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
498 '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
500 # These two tests do not include the marker, because regcomp.c no
501 # longer knows where it goes by the time this warning is emitted.
502 # See [perl #122680] regcomp warning gives wrong position of
504 '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/',
505 '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/',
509 '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/',
510 '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:zog:]{#}\x{100}/',
511 '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes (but this one isn\'t implemented) {#} m/[.zog.]{#}\x{100}/',
513 '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/',
514 '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/',
515 '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/',
516 '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/',
517 '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/',
518 '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/',
519 '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/',
520 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/',
522 '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/',
523 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/',
525 # (?c) means (?g) error won't be thrown
526 '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/',
527 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/',
529 '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/',
530 'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/',
531 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/',
533 '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/',
534 "/(?[ [ % - % ] ])/" => "",
535 "/(?[ [ : - \\x$colon_hex ] ])\\x{100}/" => "\": - \\x$colon_hex \" is more clearly written simply as \":\" {#} m/(?[ [ : - \\x$colon_hex {#}] ])\\x{100}/",
536 "/(?[ [ \\x$colon_hex - : ] ])\\x{100}/" => "\"\\x$colon_hex\ - : \" is more clearly written simply as \":\" {#} m/(?[ [ \\x$colon_hex - : {#}] ])\\x{100}/",
537 "/(?[ [ \\t - \\x$tab_hex ] ])\\x{100}/" => "\"\\t - \\x$tab_hex \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\t - \\x$tab_hex {#}] ])\\x{100}/",
538 "/(?[ [ \\x$tab_hex - \\t ] ])\\x{100}/" => "\"\\x$tab_hex\ - \\t \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\x$tab_hex - \\t {#}] ])\\x{100}/",
539 "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/",
540 "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/",
541 "/(?[ [ $low_mixed_alpha - $high_mixed_alpha ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_alpha - $high_mixed_alpha {#}] ])/",
542 "/(?[ [ $low_mixed_digit - $high_mixed_digit ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_digit - $high_mixed_digit {#}] ])/",
545 '/[:blank]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:blank{#}]\x{100}/',
546 '/[[:digit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:digit{#}]]\x{100}/', # [perl # 8904]
547 '/[[:digit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:digit:{#}foo]\x{100}/',
548 '/[[:di#it:foo]\x{100}/x' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:di#it:{#}foo]\x{100}/',
549 '/[[:dgit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:dgit{#}]]\x{100}/',
550 '/[[:dgit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:dgit:{#}foo]\x{100}/',
551 '/[[:dgt]]\x{100}/' => "", # Far enough away from a real class to not be recognized as one
552 '/[[:dgt:foo]\x{100}/' => "",
553 '/[[:DIGIT]]\x{100}/' => [ 'Assuming NOT a POSIX class since the name must be all lowercase letters {#} m/[[:DIGIT{#}]]\x{100}/',
554 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:DIGIT{#}]]\x{100}/',
556 '/[[digit]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}digit]\x{100}/',
557 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[digit{#}]\x{100}/',
559 '/[[alpha]]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}alpha]]\x{100}/',
560 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[alpha{#}]]\x{100}/',
562 '/[[^word]\x{100}/' => [ 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[^{#}word]\x{100}/',
563 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[^{#}word]\x{100}/',
564 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[^word{#}]\x{100}/',
566 '/[[ ^ : x d i g i t : ] ]\x{100}/' => [ 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ {#}^ : x d i g i t : ] ]\x{100}/',
567 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[ ^{#} : x d i g i t : ] ]\x{100}/',
568 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ {#}: x d i g i t : ] ]\x{100}/',
569 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : {#}x d i g i t : ] ]\x{100}/',
570 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : x d i g i t : ]{#} ]\x{100}/',
572 '/[foo:lower:]]\x{100}/' => 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#}:lower:]]\x{100}/',
573 '/[[;upper;]]\x{100}/' => [ 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;{#}upper;]]\x{100}/',
574 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;upper;]{#}]\x{100}/',
576 '/[foo;punct;]]\x{100}/' => [ 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#};punct;]]\x{100}/',
577 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;{#}punct;]]\x{100}/',
578 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;punct;]{#}]\x{100}/',
581 ); # See comments before this for why '\x{100}' is generally needed
583 # These need the character 'ネ' as a marker for mark_as_utf8()
584 my @warnings_utf8 = mark_as_utf8(
585 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/',
586 '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/',
587 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/ネ[:foo:]{#}ネ/',
588 '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/',
589 '/utf8 ネ (?ogc) ネ/' => [
590 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/',
591 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/',
592 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/',
597 push @warning, @warnings_utf8;
599 my @warning_only_under_strict = (
600 '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/',
601 '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/',
602 '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/',
603 '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/',
604 '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/',
605 '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/',
606 '/[\N{U+00}-A]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[\N{U+00}-A{#}]\x{100}/',
607 '/[a-\N{U+FF}]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[a-\N{U+FF}{#}]\x{100}/',
608 '/[\N{U+00}-\a]\x{100}/' => "",
609 '/[\a-\N{U+FF}]\x{100}/' => "",
610 '/[\N{U+FF}-\x{100}]/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+FF}-\x{100}{#}]/',
611 '/[\N{U+100}-\x{101}]/' => "",
613 "/[:-\\x$colon_hex]\\x{100}/" => "\":-\\x$colon_hex\" is more clearly written simply as \":\" {#} m/[:-\\x$colon_hex\{#}]\\x{100}/",
614 "/[\\x$colon_hex-:]\\x{100}/" => "\"\\x$colon_hex-:\" is more clearly written simply as \":\" {#} m/[\\x$colon_hex\-:{#}]\\x{100}/",
615 "/[\\t-\\x$tab_hex]\\x{100}/" => "\"\\t-\\x$tab_hex\" is more clearly written simply as \"\\t\" {#} m/[\\t-\\x$tab_hex\{#}]\\x{100}/",
616 "/[\\x$tab_hex-\\t]\\x{100}/" => "\"\\x$tab_hex-\\t\" is more clearly written simply as \"\\t\" {#} m/[\\x$tab_hex\-\\t{#}]\\x{100}/",
617 "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/",
618 "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/",
619 "/[$low_mixed_alpha-$high_mixed_alpha]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_alpha-$high_mixed_alpha\{#}]/",
620 "/[$low_mixed_digit-$high_mixed_digit]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_digit-$high_mixed_digit\{#}]/",
623 my @warning_utf8_only_under_strict = mark_as_utf8(
624 '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/",
625 '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/",
626 '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/",
627 '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/",
630 push @warning_only_under_strict, @warning_utf8_only_under_strict;
632 my @experimental_regex_sets = (
633 '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/',
634 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' },
635 '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/',
643 '/foo(:?{bar)/' => "",
646 '/.{/' => 'Unescaped left brace in regex is deprecated here, passed through {#} m/.{{#}/',
647 '/[x]{/' => 'Unescaped left brace in regex is deprecated here, passed through {#} m/[x]{{#}/',
648 '/\p{Latin}{/' => 'Unescaped left brace in regex is deprecated here, passed through {#} m/\p{Latin}{{#}/',
651 for my $strict ("", "use re 'strict';") {
653 # First time just use @death; but under strict we add the things that fail
654 # there. Doing it this way makes sure that 'strict' doesnt change the
655 # things that are already fatal when not under strict.
657 for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
658 push @death, $death_only_under_strict[$i], # The regex
659 $death_only_under_strict[$i+2]; # The fatal msg
661 for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
663 # Same with the utf8 versions
664 push @death, mark_as_utf8($death_utf8_only_under_strict[$i],
665 $death_utf8_only_under_strict[$i+2]);
668 for (my $i = 0; $i < @death; $i += 2) {
669 my $regex = $death[$i];
670 my $expect = fixup_expect($death[$i+1], $strict);
671 no warnings 'experimental::regex_sets';
672 no warnings 'experimental::re_strict';
675 my $eval_string = "$strict $regex";
678 like($@, qr/\Q$expect/, $eval_string);
679 }, undef, "... and died without any other warnings");
683 for my $strict ("", "no warnings 'experimental::re_strict'; use re 'strict';") {
684 my @warning_tests = @warning;
686 # Build the tests for @warning. Use the strict/non-strict versions
689 push @warning_tests, @warning_only_under_strict;
692 for (my $i = 0; $i < @warning_only_under_strict; $i += 2) {
693 if ($warning_only_under_strict[$i] =~ /\Q(?[/) {
694 push @warning_tests, $warning_only_under_strict[$i], # The regex
695 $warning_only_under_strict[$i+1];
698 push @warning_tests, $warning_only_under_strict[$i], # The regex
699 ""; # No warning because not strict
702 for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
703 push @warning_tests, $death_only_under_strict[$i], # The regex
704 $death_only_under_strict[$i+1]; # The warning
706 for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
707 push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i],
708 $death_utf8_only_under_strict[$i+1]);
712 foreach my $ref (\@warning_tests, \@experimental_regex_sets, \@deprecated) {
714 my $turn_off_warnings = "";
716 if ($ref == \@warning_tests) {
717 $warning_type = 'regexp, digit';
718 $turn_off_warnings = "no warnings 'experimental::regex_sets';";
719 $default_on = $strict;
721 elsif ($ref == \@deprecated) {
722 $warning_type = 'regexp, deprecated';
726 $warning_type = 'experimental::regex_sets';
729 for (my $i = 0; $i < @$ref; $i += 2) {
730 my $regex = $ref->[$i];
731 my @expect = fixup_expect($ref->[$i+1], $strict);
733 # A length-1 array with an empty warning means no warning gets
735 undef @expect if @expect == 1 && $expect[0] eq "";
739 #use feature 'unicode_eval';
740 #print STDERR __LINE__, ": ", "eval '$strict no warnings; $regex'", "\n";
741 eval "$strict no warnings; $regex";
743 if (is($@, "", "$strict $regex did not die")) {
744 my @got = capture_warnings(sub {
746 eval "$strict $turn_off_warnings $regex" });
748 if (! is(scalar @got, scalar @expect,
749 "... and gave expected number ($count) of warnings"))
751 if (@got < @expect) {
753 note "Expected warnings not gotten:\n\t" . join "\n\t",
754 @expect[$count .. $#expect];
757 note "Unexpected warnings gotten:\n\t" . join("\n\t",
758 @got[$count .. $#got]);
761 foreach my $i (0 .. $count - 1) {
762 if (! like($got[$i], qr/\Q$expect[$i]/,
763 "... and gave expected warning"))
767 diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'");
770 ok (0 == capture_warnings(sub {
772 eval "$strict no warnings '$warning_type'; $regex;" }
774 "... and turning off '$warning_type' warnings suppressed it");
776 # Test that whether the warning is on by default is
777 # correct. This test relies on the fact that we
778 # are outside the scope of any ‘use warnings’.
780 my @warns = capture_warnings(sub { $_ = "x";
781 eval "$strict $regex" });
782 # Warning should be on as well if is testing
783 # '(?[...])' which turns on strict
784 if ($default_on || grep { $_ =~ /\Q(?[/ } @expect ) {
785 ok @warns > 0, "... and the warning is on by default";
788 ok @warns == 0, "... and the warning is off by default";