This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/re/reg_mesg.t: Add override of warning default on/off
[perl5.git] / t / re / reg_mesg.t
1 #!./perl -w
2
3 $|=1;   # outherwise things get mixed up in output
4
5 BEGIN {
6         chdir 't' if -d 't';
7         require './test.pl';
8     set_up_inc( qw '../lib ../ext/re' );
9         eval 'require Config'; # assume defaults if this fails
10 }
11
12 skip_all_without_unicode_tables();
13
14 use strict;
15 use open qw(:utf8 :std);
16
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';
20
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
24 ## go.
25
26 sub fixup_expect ($$) {
27
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.
33
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)
37
38     my ($expect_ref, $strict) = @_;
39     return "" if $expect_ref eq "";
40
41     my @expect;
42     if (ref $expect_ref) {
43         @expect = @$expect_ref;
44     }
45     else {
46         @expect = $expect_ref;
47     }
48
49     my @new_expect;
50     foreach my $element (@expect) {
51         $element =~ s/\{\#\}/in regex; marked by <-- HERE in/;
52         $element =~ s/\{\#\}/ <-- HERE /;
53         $element .= " at ";
54         next if $element =~ s/ ^ $only_strict_marker \s* //x && ! $strict;
55         push @new_expect, $element;
56     }
57     return wantarray ? @new_expect : join "", @new_expect;
58 }
59
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.
64 ##
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.
69 my $l1   = "\x{ef}";
70 my $utf8 = "\x{30cd}";
71 utf8::encode($utf8);
72
73 sub mark_as_utf8 {
74     my @ret;
75     for (my $i = 0; $i < @_; $i += 2) {
76         my $pat = $_[$i];
77         my $msg = $_[$i+1];
78         my $l1_pat = $pat =~ s/$utf8/$l1/gr;
79         my $l1_msg;
80         $pat = "use utf8; $pat";
81
82         if (ref $msg) {
83             $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ];
84             @$msg   = map { my $c = $_; utf8::decode($c); $c } @$msg;
85         }
86         else {
87             $l1_msg = $msg =~ s/$utf8/$l1/gr;
88             utf8::decode($msg);
89         }
90         push @ret, $pat => $msg;
91
92         push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/;
93     }
94     return @ret;
95 }
96
97 my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1;
98 my $inf_p1 = $inf_m1 + 2;
99
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';
105
106 my $colon_hex = sprintf "%02X", ord(":");
107 my $tab_hex = sprintf "%02X", ord("\t");
108
109 # Key-value pairs of strings eval'd as patterns => warn/error messages that
110 # they should generate.  In some cases, the value is an array of multiple
111 # messages.  Some groups have the message(s) be default on; others, default
112 # off.  This can be overridden on an individual key basis by preceding the
113 # pattern string with either 'default_on' or 'default_off'
114 #
115 # The first set are those that should be fatal errors.
116
117 my @death =
118 (
119  '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/',
120
121  '/(?<= .*)/' =>  'Variable length lookbehind not implemented in regex m/(?<= .*)/',
122
123  '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/',
124
125  '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/',
126
127  '/(?{ 1/' => 'Missing right curly or square bracket',
128
129  '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/',
130  '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/',
131
132  '/(?(1)/'    => 'Switch (?(condition)... not terminated {#} m/(?(1){#}/',
133  '/(?(1)x/'    => 'Switch (?(condition)... not terminated {#} m/(?(1)x{#}/',
134  '/(?(1)x|y/'    => 'Switch (?(condition)... not terminated {#} m/(?(1)x|y{#}/',
135  '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/',
136
137  '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/',
138  '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/',
139  '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/',
140
141  '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/',
142
143  '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/',
144  '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
145  '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/',
146  '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/',
147  '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/',
148  '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/',
149  '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/',
150  '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/',
151  '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/',
152  '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/',
153  '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
154  '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/',
155  '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/',
156  '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/',
157  '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/',
158  '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/',
159 '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/',
160 '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/',
161 '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/',
162 '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
163
164  '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
165  '/{(}/' => 'Unmatched ( {#} m/{({#}}/',    # [perl #127599]
166
167  "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",
168
169
170  '/x**/' => 'Nested quantifiers {#} m/x**{#}/',
171
172  '/x[/' => 'Unmatched [ {#} m/x[{#}/',
173
174  '/*/', => 'Quantifier follows nothing {#} m/*{#}/',
175
176  '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/',
177
178  '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/',
179
180  '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/',
181
182  '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
183  '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
184
185  'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
186
187  '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/',
188  '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/',
189
190  '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/',
191  '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/',
192
193  '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/',
194  '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/',
195
196  '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/',
197  '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/',
198
199  '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/',
200
201  '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/',
202
203  '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/',
204
205  '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/',
206
207  '/\p/' => 'Empty \p {#} m/\p{#}/',
208  '/\P/' => 'Empty \P {#} m/\P{#}/',
209  '/\p{}/' => 'Empty \p{} {#} m/\p{{#}}/',
210  '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/',
211
212 '/a\b{cde/' => 'Missing right brace on \b{} {#} m/a\b{{#}cde/',
213 '/a\B{cde/' => 'Missing right brace on \B{} {#} m/a\B{{#}cde/',
214
215  '/\b{}/' => 'Empty \b{} {#} m/\b{}{#}/',
216  '/\B{}/' => 'Empty \B{} {#} m/\B{}{#}/',
217
218  '/\b{gc}/' => "'gc' is an unknown bound type {#} m/\\b{gc{#}}/",
219  '/\B{gc}/' => "'gc' is an unknown bound type {#} m/\\B{gc{#}}/",
220
221  '/(?[[[::]]])/' => "Syntax error in (?[...]) in regex m/(?[[[::]]])/",
222  '/(?[[[:w:]]])/' => "Syntax error in (?[...]) in regex m/(?[[[:w:]]])/",
223  '/(?[[:w:]])/' => "",
224  '/[][[:alpha:]]' => "",    # [perl #127581]
225  '/([.].*)[.]/'   => "",    # [perl #127582]
226  '/[.].*[.]/'     => "",    # [perl #127604]
227  '/(?[a])/' =>  'Unexpected character {#} m/(?[a{#}])/',
228  '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/',
229  '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/',
230  '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/',
231  '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/',
232  '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/',
233  '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/',
234  '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/',
235  '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/',
236  '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
237  '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
238  '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/',
239  '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/',
240  '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/',
241  '/(?[ ( ) ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ ( ){#} ])/',
242  '/(?[[0]+()+])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[[0]+(){#}+])/',
243  '/(?[ \p{foo} ])/' => 'Can\'t find Unicode property definition "foo" {#} m/(?[ \p{foo}{#} ])/',
244  '/(?[ \p{ foo = bar } ])/' => 'Can\'t find Unicode property definition "foo = bar" {#} m/(?[ \p{ foo = bar }{#} ])/',
245  '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/',
246  '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/',
247  '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/',
248  '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/',
249  '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/',
250  '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/',
251  '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/',
252  'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/',
253  'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/',
254  'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/',
255  'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/',
256  '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{#}}]])/',
257  'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/',
258  'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/',
259  'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/',
260  'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
261  'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/',
262  'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/',
263  'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
264  'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/',
265  'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
266  'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/',
267  'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/',
268  'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/',
269  'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/',
270  'm/(?&a/'  => 'Sequence (?&... not terminated {#} m/(?&a{#}/',
271  'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/',
272  "m/(?'/"  => "Sequence (?'... not terminated {#} m/(?'{#}/",
273  "m/(?</"  => "Sequence (?<... not terminated {#} m/(?<{#}/",
274  'm/(?&/'  => 'Sequence (?&... not terminated {#} m/(?&{#}/',
275  'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/',
276  "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/",
277  'm/\g{/'  => 'Sequence \g{... not terminated {#} m/\g{{#}/',
278  'm/\k</'  => 'Sequence \k<... not terminated {#} m/\k<{#}/',
279  'm/\cß/' => "Character following \"\\c\" must be printable ASCII",
280  '/((?# 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)/',
281  '/((?# 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)/',
282  '/(?[\ &!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ &!{#}])/',    # [perl #126180]
283  '/(?[\ +!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ +!{#}])/',    # [perl #126180]
284  '/(?[\ -!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ -!{#}])/',    # [perl #126180]
285  '/(?[\ ^!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ ^!{#}])/',    # [perl #126180]
286  '/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/',    # [perl #126180]
287  '/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/',    # [perl #126204]
288  '/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/',      # [perl #126404]
289  '/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
290  '/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
291  '/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
292  '/:{4,a}/' => 'Unescaped left brace in regex is illegal here {#} m/:{{#}4,a}/',
293  '/xa{3\,4}y/' => 'Unescaped left brace in regex is illegal here {#} m/xa{{#}3\,4}y/',
294  '/abc/xix' => "",
295  '/(?xmsixp:abc)/' => "",
296  '/(?xmsixp)abc/' => "",
297  '/(?xxxx:abc)/' => "",
298  '/(?<=/' => 'Sequence (?... not terminated {#} m/(?<={#}/',                        # [perl #128170]
299
300 );
301
302 # These are messages that are warnings when not strict; death under 'use re
303 # "strict".  See comment before @warnings as to why some have a \x{100} in
304 # them.  This array has 3 elements per construct.  [0] is the regex to use;
305 # [1] is the message under no strict, and [2] is under strict.
306 my @death_only_under_strict = (
307     'm/\xABC/' => "",
308                => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/',
309     'm/[\xABC]/' => "",
310                  => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/',
311
312     # XXX This is a confusing error message.  The G isn't ignored; it just
313     # terminates the \x.  Also some messages below are missing the <-- HERE,
314     # aren't all category 'regexp'.  (Hence we have to turn off 'digit'
315     # messages as well below)
316     'm/\xAG/' => 'Illegal hexadecimal digit \'G\' ignored',
317               => 'Non-hex character {#} m/\xAG{#}/',
318     'm/[\xAG]/' => 'Illegal hexadecimal digit \'G\' ignored',
319                 => 'Non-hex character {#} m/[\xAG{#}]/',
320     'm/\o{789}/' => 'Non-octal character \'8\'.  Resolved as "\o{7}"',
321                  => 'Non-octal character {#} m/\o{78{#}9}/',
322     'm/[\o{789}]/' => 'Non-octal character \'8\'.  Resolved as "\o{7}"',
323                    => 'Non-octal character {#} m/[\o{78{#}9}]/',
324     'm/\x{}/' => "",
325               => 'Number with no digits {#} m/\x{}{#}/',
326     'm/[\x{}]/' => "",
327                 => 'Number with no digits {#} m/[\x{}{#}]/',
328     'm/\x{ABCDEFG}/' => 'Illegal hexadecimal digit \'G\' ignored',
329                      => 'Non-hex character {#} m/\x{ABCDEFG{#}}/',
330     'm/[\x{ABCDEFG}]/' => 'Illegal hexadecimal digit \'G\' ignored',
331                        => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/',
332     "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/',
333                        => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/',
334     'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
335                        => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
336     'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
337                        => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
338     'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
339                         => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
340     'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
341                         => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
342     '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}{#}]/',
343                                        => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[^\N{U+100.300{#}}]/',
344     '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}{#}]/',
345                                             => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/',
346     '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}]/',
347                                                   => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/',
348     '/[\08]/'   => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/',
349                 => 'Need exactly 3 octal digits {#} m/[\08{#}]/',
350     '/[\018]/'  => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/',
351                 => 'Need exactly 3 octal digits {#} m/[\018{#}]/',
352     '/[\_\0]/'  => "",
353                 => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/',
354     '/[\07]/'   => "",
355                 => 'Need exactly 3 octal digits {#} m/[\07]{#}/',
356     '/[\0005]/' => "",
357                 => 'Need exactly 3 octal digits {#} m/[\0005]{#}/',
358     '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/',
359                           'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/',
360                          ],
361                       => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/',
362     '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
363                       => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
364     '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
365                       => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
366     '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
367                        => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
368     '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
369                        => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
370     '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
371                              => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
372     '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
373                              => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
374     '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
375                                      => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
376     '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
377                                      => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
378     '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/',
379                       => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/',
380 );
381
382 # These need the character 'ネ' as a marker for mark_as_utf8()
383 my @death_utf8 = mark_as_utf8(
384  '/ネ(?<= .*)/' =>  'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/',
385
386  '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/',
387
388  '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/',
389
390  '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/',
391
392  '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/',
393
394  '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/',
395
396  '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/',
397
398  '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/',
399  '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/',
400  '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/',
401  '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/',
402 '/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/',
403 '/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/',
404 '/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/',
405
406  '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/',
407
408  "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/",
409
410
411  '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/',
412
413  '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/',
414
415  '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/',
416
417  '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/',
418
419  '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/',
420
421  '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/',
422
423  'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/',
424
425  '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/',
426  '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/',
427  '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/',
428
429  '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/',
430  '/ネ[[:ネ:]]ネ/' => "",
431
432  '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/',
433
434  '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/',
435
436  '/ネ(?[[[:ネ]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ]]])ネ/",
437  '/ネ(?[[[:ネ: ])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ: ])ネ/",
438  '/ネ(?[[[::]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[::]]])ネ/",
439  '/ネ(?[[[:ネ:]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ:]]])ネ/",
440  '/ネ(?[[:ネ:]])ネ/' => "",
441  '/ネ(?[ネ])ネ/' =>  'Unexpected character {#} m/ネ(?[ネ{#}])ネ/',
442  '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/',
443  '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/',
444  '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/',
445  '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/',
446  '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/',
447  '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/',
448  '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/',
449  '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/',
450  '/(?[ \p{ネ} ])/' => 'Can\'t find Unicode property definition "ネ" {#} m/(?[ \p{ネ}{#} ])/',
451  '/(?[ \p{ ネ = bar } ])/' => 'Can\'t find Unicode property definition "ネ = bar" {#} m/(?[ \p{ ネ = bar }{#} ])/',
452  '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/',
453  '/(?[ \t + \e # ネ This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # ネ This was supposed to be a comment ])/',
454  'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>,
455  '/\cネ/' => "Character following \"\\c\" must be printable ASCII",
456  '/\b{ネ}/' => "'ネ' is an unknown bound type {#} m/\\b{ネ{#}}/",
457  '/\B{ネ}/' => "'ネ' is an unknown bound type {#} m/\\B{ネ{#}}/",
458 );
459 push @death, @death_utf8;
460
461 my @death_utf8_only_under_strict = (
462     "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/',
463                    => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/',
464     'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
465                      => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
466     'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
467                      => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
468     'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
469                       => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
470     '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
471                            => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
472     '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
473                     => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
474     '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/',
475                    => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/',
476 );
477 # Tests involving a user-defined charnames translator are in pat_advanced.t
478
479 # In the following arrays of warnings, the value can be an array of things to
480 # expect.  If the empty string, it means no warning should be raised.
481
482
483 # Key-value pairs of code/error of code that should have non-fatal regexp
484 # warnings.  Most currently have \x{100} appended to them to force them to be
485 # upgraded to UTF-8, and the first pass restarted.  Previously this would
486 # cause some warnings to be output twice.  This tests that that behavior has
487 # been fixed.
488
489 my @warning = (
490     'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
491     '/\b{g}/a' => "Using /u for '\\b{g}' instead of /a {#} m/\\b{g}{#}/",
492     '/\B{gcb}/a' => "Using /u for '\\B{gcb}' instead of /a {#} m/\\B{gcb}{#}/",
493     'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
494     'm/[[:cntrl:]][:^ascii:]\x{100}/' =>  'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/',
495     'm/[[:ascii]]\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/[[:ascii{#}]]\\x{100}/",
496     'm/(?[[:word]])\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/(?[[:word{#}]])\\x{100}/",
497     "m'\\y\\x{100}'"     => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
498     '/x{3,1}/'   => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
499     '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',
500     '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/',
501     '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
502     'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
503     '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
504
505     # These two tests do not include the marker, because regcomp.c no
506     # longer knows where it goes by the time this warning is emitted.
507     # See [perl #122680] regcomp warning gives wrong position of
508     # problem.
509     '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/',
510     '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/',
511
512     '/\_/' => "",
513     '/[\006]/' => "",
514     '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/',
515     '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:zog:]{#}\x{100}/',
516     '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes (but this one isn\'t implemented) {#} m/[.zog.]{#}\x{100}/',
517     '/[a-b]/' => "",
518     '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/',
519     '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/',
520     '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/',
521     '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/',
522     '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/',
523     '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/',
524     '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/',
525                     'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/',
526                   ],
527     '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/',
528                     'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/',
529                   ],
530       # (?c) means (?g) error won't be thrown
531      '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/',
532                       'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/',
533                     ],
534     '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/',
535                     'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/',
536                     'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/',
537                   ],
538     '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/',
539     "/(?[ [ % - % ] ])/" => "",
540     "/(?[ [ : - \\x$colon_hex ] ])\\x{100}/" => "\": - \\x$colon_hex \" is more clearly written simply as \":\" {#} m/(?[ [ : - \\x$colon_hex {#}] ])\\x{100}/",
541     "/(?[ [ \\x$colon_hex - : ] ])\\x{100}/" => "\"\\x$colon_hex\ - : \" is more clearly written simply as \":\" {#} m/(?[ [ \\x$colon_hex - : {#}] ])\\x{100}/",
542     "/(?[ [ \\t - \\x$tab_hex ] ])\\x{100}/" => "\"\\t - \\x$tab_hex \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\t - \\x$tab_hex {#}] ])\\x{100}/",
543     "/(?[ [ \\x$tab_hex - \\t ] ])\\x{100}/" => "\"\\x$tab_hex\ - \\t \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\x$tab_hex - \\t {#}] ])\\x{100}/",
544     "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/",
545     "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/",
546     "/(?[ [ $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 {#}] ])/",
547     "/(?[ [ $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 {#}] ])/",
548     "/[alnum]/" => "",
549     "/[^alnum]/" => "",
550     '/[:blank]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:blank{#}]\x{100}/',
551     '/[[:digit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:digit{#}]]\x{100}/', # [perl # 8904]
552     '/[[:digit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:digit:{#}foo]\x{100}/',
553     '/[[:di#it:foo]\x{100}/x' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:di#it:{#}foo]\x{100}/',
554     '/[[:dgit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:dgit{#}]]\x{100}/',
555     '/[[:dgit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:dgit:{#}foo]\x{100}/',
556     '/[[:dgt]]\x{100}/' => "",      # Far enough away from a real class to not be recognized as one
557     '/[[:dgt:foo]\x{100}/' => "",
558     '/[[:DIGIT]]\x{100}/' => [ 'Assuming NOT a POSIX class since the name must be all lowercase letters {#} m/[[:DIGIT{#}]]\x{100}/',
559                                'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:DIGIT{#}]]\x{100}/',
560                            ],
561     '/[[digit]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}digit]\x{100}/',
562                              'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[digit{#}]\x{100}/',
563                            ],
564     '/[[alpha]]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}alpha]]\x{100}/',
565                               'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[alpha{#}]]\x{100}/',
566                            ],
567     '/[[^word]\x{100}/' => [ 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[^{#}word]\x{100}/',
568                               'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[^{#}word]\x{100}/',
569                               'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[^word{#}]\x{100}/',
570                             ],
571     '/[[   ^   :   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}/',
572                                                'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[   ^{#}   :   x d i g i t   :   ]   ]\x{100}/',
573                                                'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   {#}:   x d i g i t   :   ]   ]\x{100}/',
574                                                'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   :   {#}x d i g i t   :   ]   ]\x{100}/',
575                                                'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   :   x d i g i t   :   ]{#}   ]\x{100}/',
576                                                $only_strict_marker . 'Unescaped literal \']\' {#} m/[[   ^   :   x d i g i t   :   ]   ]{#}\x{100}/',
577                             ],
578     '/[foo:lower:]]\x{100}/' => 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#}:lower:]]\x{100}/',
579     '/[[;upper;]]\x{100}/' => [ 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;{#}upper;]]\x{100}/',
580                                 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;upper;]{#}]\x{100}/',
581                               ],
582     '/[foo;punct;]]\x{100}/' => [ 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#};punct;]]\x{100}/',
583                                   'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;{#}punct;]]\x{100}/',
584                                   'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;punct;]{#}]\x{100}/',
585                                 ],
586
587 ); # See comments before this for why '\x{100}' is generally needed
588
589 # These need the character 'ネ' as a marker for mark_as_utf8()
590 my @warnings_utf8 = mark_as_utf8(
591     'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/',
592     '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/',
593     'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/ネ[:foo:]{#}ネ/',
594     '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/',
595     '/utf8 ネ (?ogc) ネ/' => [
596         'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/',
597         'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/',
598         'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/',
599     ],
600
601 );
602
603 push @warning, @warnings_utf8;
604
605 my @warning_only_under_strict = (
606     '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/',
607     '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/',
608     '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/',
609     '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/',
610     '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/',
611     '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/',
612     '/[\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}/',
613     '/[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}/',
614     '/[\N{U+00}-\a]\x{100}/' => "",
615     '/[\a-\N{U+FF}]\x{100}/' => "",
616     '/[\N{U+FF}-\x{100}]/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+FF}-\x{100}{#}]/',
617     '/[\N{U+100}-\x{101}]/' => "",
618     "/[%-%]/" => "",
619     "/[:-\\x$colon_hex]\\x{100}/" => "\":-\\x$colon_hex\" is more clearly written simply as \":\" {#} m/[:-\\x$colon_hex\{#}]\\x{100}/",
620     "/[\\x$colon_hex-:]\\x{100}/" => "\"\\x$colon_hex-:\" is more clearly written simply as \":\" {#} m/[\\x$colon_hex\-:{#}]\\x{100}/",
621     "/[\\t-\\x$tab_hex]\\x{100}/" => "\"\\t-\\x$tab_hex\" is more clearly written simply as \"\\t\" {#} m/[\\t-\\x$tab_hex\{#}]\\x{100}/",
622     "/[\\x$tab_hex-\\t]\\x{100}/" => "\"\\x$tab_hex-\\t\" is more clearly written simply as \"\\t\" {#} m/[\\x$tab_hex\-\\t{#}]\\x{100}/",
623     "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/",
624     "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/",
625     "/[$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\{#}]/",
626     "/[$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\{#}]/",
627     '/\b<GCB}/' => 'Unescaped literal \'}\' {#} m/\b<GCB}{#}/',
628     '/[ ]def]/' => 'Unescaped literal \']\' {#} m/[ ]def]{#}/',
629 );
630
631 my @warning_utf8_only_under_strict = mark_as_utf8(
632  '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/",
633  '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/",
634  '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/",
635  '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/",
636  '/ネ(?[ [ 𝟘 - 𝟡 ] ])/; #no latin1' => "",
637  '/ネ(?[ [ 𝟧 - 𝟱 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟱 {#}] ])/",
638  '/ネ(?[ [ 𝟧 - 𝟰 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟰 {#}] ])/",
639 );
640
641 push @warning_only_under_strict, @warning_utf8_only_under_strict;
642
643 my @experimental_regex_sets = (
644     '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/',
645     'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' },
646     '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/',
647 );
648
649 my @deprecated = (
650  '/^{/'          => "",
651  '/foo|{/'       => "",
652  '/foo|^{/'      => "",
653  '/foo({bar)/'   => "",
654  '/foo(:?{bar)/' => "",
655  '/\s*{/'        => "",
656  '/a{3,4}{/'     => "",
657  '/.{/'         => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/.{{#}/',
658  '/[x]{/'       => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/[x]{{#}/',
659  '/\p{Latin}{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\p{Latin}{{#}/',
660  '/\\${[^\\}]*}/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\\${{#}[^\\}]*}/',
661 );
662
663 for my $strict ("", "use re 'strict';") {
664
665     # First time just use @death; but under strict we add the things that fail
666     # there.  Doing it this way makes sure that 'strict' doesnt change the
667     # things that are already fatal when not under strict.
668     if ($strict) {
669         for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
670             push @death, $death_only_under_strict[$i],    # The regex
671                          $death_only_under_strict[$i+2];  # The fatal msg
672         }
673         for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
674
675             # Same with the utf8 versions
676             push @death, mark_as_utf8($death_utf8_only_under_strict[$i],
677                                       $death_utf8_only_under_strict[$i+2]);
678         }
679     }
680     for (my $i = 0; $i < @death; $i += 2) {
681         my $regex = $death[$i] =~ s/ default_ (on | off) //rx;
682         my $expect = fixup_expect($death[$i+1], $strict);
683         no warnings 'experimental::regex_sets';
684         no warnings 'experimental::re_strict';
685
686         warning_is(sub {
687                     my $eval_string = "$strict $regex";
688                     $_ = "x";
689                     eval $eval_string;
690                     like($@, qr/\Q$expect/, $eval_string);
691                 }, undef, "... and died without any other warnings");
692     }
693 }
694
695 for my $strict ("",  "no warnings 'experimental::re_strict'; use re 'strict';") {
696     my @warning_tests = @warning;
697
698     # Build the tests for @warning.  Use the strict/non-strict versions
699     # appropriately.
700     if ($strict) {
701         push @warning_tests, @warning_only_under_strict;
702     }
703     else {
704         for (my $i = 0; $i < @warning_only_under_strict; $i += 2) {
705
706             # (?[ ]) are always under strict
707             if ($warning_only_under_strict[$i] =~ /\Q(?[/) {
708                 push @warning_tests, $warning_only_under_strict[$i],  # The regex
709                                     $warning_only_under_strict[$i+1];
710             }
711             else {
712                 push @warning_tests, $warning_only_under_strict[$i],  # The regex
713                                     "";    # No warning because not strict
714             }
715         }
716         for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
717             push @warning_tests, $death_only_under_strict[$i],    # The regex
718                                  $death_only_under_strict[$i+1];  # The warning
719         }
720         for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
721             push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i],
722                                         $death_utf8_only_under_strict[$i+1]);
723         }
724     }
725
726     foreach my $ref (\@warning_tests, \@experimental_regex_sets, \@deprecated) {
727         my $warning_type;
728         my $turn_off_warnings = "";
729         my $default_on;
730         if ($ref == \@warning_tests) {
731             $warning_type = 'regexp, digit';
732             $turn_off_warnings = "no warnings 'experimental::regex_sets';";
733             $default_on = $strict;
734         }
735         elsif ($ref == \@deprecated) {
736             $warning_type = 'regexp, deprecated';
737             $default_on = 1;
738         }
739         else {
740             $warning_type = 'experimental::regex_sets';
741             $default_on = 1;
742         }
743         for (my $i = 0; $i < @$ref; $i += 2) {
744             my $this_default_on = $default_on;
745             my $regex = $ref->[$i];
746             if ($regex =~ s/ default_ (on | off) //x) {
747                 $this_default_on = $1 eq 'on';
748             }
749             my @expect = fixup_expect($ref->[$i+1], $strict);
750
751             # A length-1 array with an empty warning means no warning gets
752             # generated at all.
753             undef @expect if @expect == 1 && $expect[0] eq "";
754
755             {
756                 $_ = "x";
757                 #use feature 'unicode_eval';
758                 #print STDERR __LINE__, ": ", "eval '$strict no warnings; $regex'", "\n";
759                 eval "$strict no warnings; $regex";
760             }
761             if (is($@, "", "$strict $regex did not die")) {
762                 my @got = capture_warnings(sub {
763                                         $_ = "x";
764                                         eval "$strict $turn_off_warnings $regex" });
765                 my $count = @expect;
766                 if (! is(scalar @got, scalar @expect,
767                             "... and gave expected number ($count) of warnings"))
768                 {
769                     if (@got < @expect) {
770                         $count = @got;
771                         note "Expected warnings not gotten:\n\t" . join "\n\t",
772                                                     @expect[$count .. $#expect];
773                     }
774                     else {
775                         note "Unexpected warnings gotten:\n\t" . join("\n\t",
776                                                          @got[$count .. $#got]);
777                     }
778                 }
779                 foreach my $i (0 .. $count - 1) {
780                     if (! like($got[$i], qr/\Q$expect[$i]/,
781                                                "... and gave expected warning"))
782                     {
783                         chomp($got[$i]);
784                         chomp($expect[$i]);
785                         diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'");
786                     }
787                     else {
788                         ok (0 == capture_warnings(sub {
789                             $_ = "x";
790                             eval "$strict no warnings '$warning_type'; $regex;" }
791                            ),
792                            "... and turning off '$warning_type' warnings suppressed it");
793
794                         # Test that whether the warning is on by default is
795                         # correct.  This test relies on the fact that we
796                         # are outside the scope of any ‘use warnings’.
797                         local $^W;
798                         my @warns = capture_warnings(sub { $_ = "x";
799                                                         eval "$strict $regex" });
800                         # Warning should be on as well if is testing
801                         # '(?[...])' which turns on strict
802                         if ($this_default_on || grep { $_ =~ /\Q(?[/ } @expect ) {
803                            ok @warns > 0, "... and the warning is on by default";
804                         }
805                         else {
806                          ok @warns == 0, "... and the warning is off by default";
807                         }
808                     }
809                 }
810             }
811         }
812     }
813 }
814
815 done_testing();