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