xref: /openbsd-src/gnu/usr.bin/perl/t/re/reg_mesg.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1#!./perl -w
2
3$|=1;   # outherwise things get mixed up in output
4
5BEGIN {
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
12skip_all_without_unicode_tables();
13
14use strict;
15use open qw(:utf8 :std);
16
17# Show that it works when all warnings are enabled upon invocation.  This file
18# includes tests that the default warnings are enabled by default, and the
19# non-default ones aren't.
20use warnings;
21BEGIN { ${^WARNING_BITS} = undef }  # Kludge to restore default warnings
22
23# NOTE:
24# This file uses display_rx() from t/test.pl, which escapes
25# non-printable codepoints and percentage symbols as non-standard
26# "%x{01+aa+bc+02}" style sequences.  We do this as we may be testing
27# malformed utf8 sequences or other non-printable characters which we
28# want to distinguish from any actual regex pattern escape sequences,
29# while at the same time we don't want to emit any non-printable
30# sequences to a terminal as literals where they may cause problems.
31# Thus "\x{01}" means the string contained six codepoints making up a
32# normal "\x{...}" style escape sequence whereas "%x{01}" means the string
33# contained a single codepoint and "%x{01+02}" means it contained two
34# codepoints, etc. - Yves
35
36# Kind of a kludge to mark warnings to be expected only if we are testing
37# under "use re 'strict'"
38my $only_strict_marker = ':expected_only_under_strict';
39
40## If the markers used are changed (search for "MARKER1" in regcomp.c),
41## update only these two regexs, and leave the {#} in the @death/@warning
42## arrays below. The {#} is a meta-marker -- it marks where the marker should
43## go.
44
45sub fixup_expect ($$) {
46
47    # Fixes up the expected results by inserting the boiler plate text.
48    # Returns empty string if that is what is expected.  Otherwise, handles
49    # either a scalar, turning it into a single element array; or a ref to an
50    # array, adjusting each element.  If called in array context, returns an
51    # array, otherwise the join of all elements.
52
53    # The string $only_strict_marker will be removed from any expect line it
54    # begins, and if $strict is not true, that expect line will be removed
55    # from the output (hence won't be expected)
56
57    my ($expect_ref, $strict) = @_;
58    return "" if $expect_ref eq "";
59
60    my @expect;
61    if (ref $expect_ref) {
62        @expect = @$expect_ref;
63    }
64    else {
65        @expect = $expect_ref;
66    }
67
68    my @new_expect;
69    foreach my $element (@expect) {
70        $element =~ s/\{\#\}/in regex; marked by <-- HERE in/;
71        $element =~ s/\{\#\}/ <-- HERE /;
72        $element .= " at ";
73        next if $element =~ s/ ^ $only_strict_marker \s* //x && ! $strict;
74        push @new_expect, $element;
75    }
76    return wantarray ? @new_expect : join "", @new_expect;
77}
78
79sub add_markers {
80    my ($element)= @_;
81    $element =~ s/ at .* line \d+\.?\n$//;
82    $element =~ s/in regex; marked by <-- HERE in/{#}/;
83    $element =~ s/ <-- HERE /{#}/;
84    return $element;
85}
86
87## Because we don't "use utf8" in this file, we need to do some extra legwork
88## for the utf8 tests: Prepend 'use utf8' to the pattern, and mark the strings
89## to check against as UTF-8, but for this all to work properly, the character
90## 'ネ' (U+30CD) is required in each pattern somewhere as a marker.
91##
92## This also creates a second variant of the tests to check if the
93## latin1 error messages are working correctly.  Because we don't 'use utf8',
94## we can't tell if something is UTF-8 or Latin1, so you need the suffix
95## '; no latin1' to not have the second variant.
96my $l1   = "\x{ef}";
97my $utf8 = "\x{30cd}";
98utf8::encode($utf8);
99
100sub mark_as_utf8 {
101    my @ret;
102    for (my $i = 0; $i < @_; $i += 2) {
103        my $pat = $_[$i];
104        my $msg = $_[$i+1];
105        my $l1_pat = $pat =~ s/$utf8/$l1/gr;
106        my $l1_msg;
107        $pat = "use utf8; $pat";
108
109        if (ref $msg) {
110            $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ];
111            @$msg   = map { my $c = $_; utf8::decode($c); $c } @$msg;
112        }
113        else {
114            $l1_msg = $msg =~ s/$utf8/$l1/gr;
115            utf8::decode($msg);
116        }
117        push @ret, $pat => $msg;
118
119        push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/;
120    }
121    return @ret;
122}
123
124my $inf_m1 = ($Config::Config{reg_infty} || ((1<<31)-1)) - 1;
125my $inf_p1 = $inf_m1 + 2;
126
127my $B_hex = sprintf("\\x%02X", ord "B");
128my $low_mixed_alpha = ('A' lt 'a') ? 'A' : 'a';
129my $high_mixed_alpha = ('A' lt 'a') ? 'a' : 'A';
130my $low_mixed_digit = ('A' lt '0') ? 'A' : '0';
131my $high_mixed_digit = ('A' lt '0') ? '0' : 'A';
132
133my $colon_hex = sprintf "%02X", ord(":");
134my $tab_hex = sprintf "%02X", ord("\t");
135
136# Key-value pairs of strings eval'd as patterns => warn/error messages that
137# they should generate.  In some cases, the value is an array of multiple
138# messages.  Some groups have the message(s) be default on; others, default
139# off.  This can be overridden on an individual key basis by preceding the
140# pattern string with either 'default_on' or 'default_off'
141#
142# The first set are those that should be fatal errors.
143
144my $bug133423 = "(?[(?^:(?[\\\x00]))\\]\x00|2[^^]\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80])R.\\670";
145
146my @death =
147(
148 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/',
149
150 '/(?<= .*)/' =>  'Lookbehind longer than 255 not implemented in regex m/(?<= .*)/',
151
152 '/(?<= a+)/' =>  'Lookbehind longer than 255 not implemented in regex m/(?<= a+)/',
153 '/(?<= a{255})/' =>  'Lookbehind longer than 255 not implemented in regex m/(?<= a{255})/',
154 '/(?<= a{0,255})/' =>  'Lookbehind longer than 255 not implemented in regex m/(?<= a{0,255})/',
155 '/(?<= a{200}b{55})/' =>  'Lookbehind longer than 255 not implemented in regex m/(?<= a{200}b{55})/',
156
157 '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/',
158 '/(?<= (?&x))(?<x>x+)/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= (?&x))(?<x>x+)/',
159
160 '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/',
161
162 '/(?{ 1/' => 'Missing right curly or square bracket',
163
164 '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/',
165 '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/',
166
167 '/(?(1)/'    => 'Switch (?(condition)... not terminated {#} m/(?(1){#}/',
168 '/(?(1)x/'    => 'Switch (?(condition)... not terminated {#} m/(?(1)x{#}/',
169 '/(?(1)x|y/'    => 'Switch (?(condition)... not terminated {#} m/(?(1)x|y{#}/',
170 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/',
171
172 '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/',
173 '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/',
174 '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/',
175
176 '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/',
177
178 '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/',
179 '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
180 '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/',
181 '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/',
182 '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/',
183 '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/',
184 '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/',
185 '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/',
186 '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/',
187 '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/',
188 '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
189 '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/',
190 '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/',
191 '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/',
192 '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/',
193 '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/',
194'/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/',
195'/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/',
196'/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/',
197'/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
198
199 '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
200 '/{(}/' => 'Unmatched ( {#} m/{({#}}/',    # [perl #127599]
201
202 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{$inf_p1\{#}}/",
203 "/x{$inf_p1,}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{$inf_p1\{#},}/",
204 "/x{01,2}/" => "Invalid quantifier in {,} {#} m/x{01{#},2}/",
205 "/x{1,02}/" => "Invalid quantifier in {,} {#} m/x{1,02{#}}/",
206
207
208 '/x**/' => 'Nested quantifiers {#} m/x**{#}/',
209
210 '/x[/' => 'Unmatched [ {#} m/x[{#}/',
211
212 '/*/', => 'Quantifier follows nothing {#} m/*{#}/',
213
214 '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/',
215
216 '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/',
217
218 '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/',
219
220 '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
221 '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
222 '/\g{-abc}/' => 'Group name must start with a non-digit word character {#} m/\g{-{#}abc}/',
223 '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
224
225 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
226
227 '/\x{ 1 /' => 'Missing right brace on \x{} {#} m/\x{ 1{#} /',
228 '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/',
229
230 '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/',
231 '/[\x{ A ]/' => 'Missing right brace on \x{} {#} m/[\x{ A{#} ]/',
232
233 '/\o{ 1 /' => 'Missing right brace on \o{} {#} m/\o{ 1{#} /',
234 '/\o{X/'   => 'Missing right brace on \o{} {#} m/\o{{#}X/',
235
236 '/[\o{X]/' => 'Missing right brace on \o{} {#} m/[\o{{#}X]/',
237 '/[\o{ 7 ]/' => 'Missing right brace on \o{} {#} m/[\o{ 7{#} ]/',
238
239 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/',
240
241 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/',
242
243 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/',
244
245 '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/',
246
247 '/\p/' => 'Empty \p {#} m/\p{#}/',
248 '/\P/' => 'Empty \P {#} m/\P{#}/',
249 '/\p{}/' => 'Empty \p{} {#} m/\p{{#}}/',
250 '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/',
251
252'/a\b{cde/' => 'Missing right brace on \b{} {#} m/a\b{{#}cde/',
253'/a\B{cde/' => 'Missing right brace on \B{} {#} m/a\B{{#}cde/',
254
255 '/\b{}/' => 'Empty \b{} {#} m/\b{}{#}/',
256 '/\B{}/' => 'Empty \B{} {#} m/\B{}{#}/',
257
258 '/\b{gc}/' => "'gc' is an unknown bound type {#} m/\\b{gc{#}}/",
259 '/\B{gc}/' => "'gc' is an unknown bound type {#} m/\\B{gc{#}}/",
260
261 '/(?[[[::]]])/' => "Unexpected ']' with no following ')' in (?[... {#} m/(?[[[::]]{#}])/",
262 '/(?[[[:w:]]])/' => "Unexpected ']' with no following ')' in (?[... {#} m/(?[[[:w:]]{#}])/",
263 '/(?[a])/' =>  'Unexpected character {#} m/(?[a{#}])/',
264 '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/',
265 '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/',
266 '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/',
267 '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/',
268 '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/',
269 '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/',
270 '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/',
271 '/(?[ \o{} ])/' => 'Empty \o{} {#} m/(?[ \o{}{#} ])/',
272 '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
273 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
274 '/(?[ \x{} ])/' => 'Empty \x{} {#} m/(?[ \x{}{#} ])/',
275 '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/',
276 '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/',
277 '/(?[ ( ) ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ ( ){#} ])/',
278 '/(?[[0]+()+])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[[0]+(){#}+])/',
279 '/(?[ \p{foo} ])/' => 'Can\'t find Unicode property definition "foo" {#} m/(?[ \p{foo}{#} ])/',
280 '/(?[ \p{ foo = bar } ])/' => 'Can\'t find Unicode property definition "foo = bar" {#} m/(?[ \p{ foo = bar }{#} ])/',
281 '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/',
282 '/(?[ \t ]/' => "Unexpected ']' with no following ')' in (?[... {#} m/(?[ \\t ]{#}/",
283 '/(?[ [ \t ]/' => "Syntax error in (?[...]) {#} m/(?[ [ \\t ]{#}/",
284 '/(?[ \t ] ]/' => "Unexpected ']' with no following ')' in (?[... {#} m/(?[ \\t ]{#} ]/",
285 '/(?[ [ ] ]/' => "Syntax error in (?[...]) {#} m/(?[ [ ] ]{#}/",
286 '/(?[ \t + \e # This was supposed to be a comment ])/' =>
287    "Syntax error in (?[...]) {#} m/(?[ \\t + \\e # This was supposed to be a comment ]){#}/",
288 '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/',
289 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/',
290 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/',
291 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/',
292 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/',
293 'm/(?[[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} here is restricted to one character {#} m/(?[[^\N{U+100.300{#}}]])/',
294 'm/(?[ \p{Digit} & (?^(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?^(...) not recognized {#} m/(?[ \p{Digit} & (?^({#}?[ \p{Thai} | \p{Lao} ]))])/',
295 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Unexpected character {#} m/(?[ \p{Digit} & (?{#}(?[ \p{Thai} | \p{Lao} ]))])/',
296 'm/\p{Is_Is_Any}/' => 'Unknown user-defined property name \p{main::Is_Is_Any}',
297 'm/\o{/' => 'Missing right brace on \o{} {#} m/\o{{#}/',
298 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
299 'm/\o{}/' => 'Empty \o{} {#} m/\o{}{#}/',
300 'm/[\o{]/' => 'Missing right brace on \o{} {#} m/[\o{{#}]/',
301 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
302 'm/[\o{}]/' => 'Empty \o{} {#} m/[\o{}{#}]/',
303 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
304 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/',
305 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/',
306 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/',
307 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/',
308 'm/(?&a/'  => 'Sequence (?&... not terminated {#} m/(?&a{#}/',
309 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/',
310 "m/(?'/"  => "Sequence (?'... not terminated {#} m/(?'{#}/",
311 "m/(?</"  => "Sequence (?<... not terminated {#} m/(?<{#}/",
312 'm/(?&/'  => 'Sequence (?&... not terminated {#} m/(?&{#}/',
313 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/',
314 "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/",
315 'm/\g{/'  => 'Sequence \g{... not terminated {#} m/\g{{#}/',
316 'm/\k</'  => 'Sequence \k<... not terminated {#} m/\k<{#}/',
317 '/((?# 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)/',
318 '/((?# 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)/',
319 '/((?# This is a comment in the middle of a token)*script_run:foo)/' => 'In \'(*...)\', the \'(\' and \'*\' must be adjacent {#} m/((?# This is a comment in the middle of a token)*{#}script_run:foo)/',
320
321 '/(*script_runfoo)/' => 'Unknown \'(*...)\' construct \'script_runfoo\' {#} m/(*script_runfoo){#}/',
322 '/(*srfoo)/' => 'Unknown \'(*...)\' construct \'srfoo\' {#} m/(*srfoo){#}/',
323 '/(*script_run)/' => '\'(*script_run\' requires a terminating \':\' {#} m/(*script_run{#})/',
324 '/(*sr)/' => '\'(*sr\' requires a terminating \':\' {#} m/(*sr{#})/',
325 '/(*pla)/' => '\'(*pla\' requires a terminating \':\' {#} m/(*pla{#})/',
326 '/(*script_run/' => 'Unterminated \'(*...\' construct {#} m/(*script_run{#}/',
327 '/(*sr/' => 'Unterminated \'(*...\' construct {#} m/(*sr{#}/',
328 '/(*script_run:foo/' => 'Unterminated \'(*...\' argument {#} m/(*script_run:foo{#}/',
329 '/(*sr:foo/' => 'Unterminated \'(*...\' argument {#} m/(*sr:foo{#}/',
330 '/(?[\ &!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ &!{#}])/',    # [perl #126180]
331 '/(?[\ +!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ +!{#}])/',    # [perl #126180]
332 '/(?[\ -!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ -!{#}])/',    # [perl #126180]
333 '/(?[\ ^!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ ^!{#}])/',    # [perl #126180]
334 '/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/',    # [perl #126180]
335 '/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/',    # [perl #126204]
336 '/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/',      # [perl #126404]
337 '/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
338 '/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
339 '/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
340 '/(?<=/' => 'Sequence (?<=... not terminated {#} m/(?<={#}/',                        # [perl #128170]
341 '/(?<!/' => 'Sequence (?<!... not terminated {#} m/(?<!{#}/',
342 '/(?!/' => 'Sequence (?!... not terminated {#} m/(?!{#}/',
343 '/(?=/' => 'Sequence (?=... not terminated {#} m/(?={#}/',
344 '/\p{vertical  tab}/' => 'Can\'t find Unicode property definition "vertical  tab" {#} m/\\p{vertical  tab}{#}/', # [perl #132055]
345 "/$bug133423/" => "Unexpected ']' with no following ')' in (?[... {#} m/(?[(?^:(?[\\�]))\\]{#}�|2[^^]\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80])R.\\670/",
346 '/[^/' => 'Unmatched [ {#} m/[{#}^/', # [perl #133767]
347 '/\p{Is_Other_Alphabetic=F}/ ' => 'Can\'t find Unicode property definition "Is_Other_Alphabetic=F" {#} m/\p{Is_Other_Alphabetic=F}{#}/',
348 '/\p{Is_Other_Alphabetic=F}/ ' => 'Can\'t find Unicode property definition "Is_Other_Alphabetic=F" {#} m/\p{Is_Other_Alphabetic=F}{#}/',
349 '/\x{100}(?(/' => 'Unknown switch condition (?(...)) {#} m/\\x{100}(?({#}/', # [perl #133896]
350 '/(?[\N{KEYCAP DIGIT NINE}/' => '\N{} here is restricted to one character {#} m/(?[\\N{U+39.FE0F.20E3{#}}/', # [perl #133988]
351 '/0000000000000000[\N{U+0.00}0000/' => 'Unmatched [ {#} m/0000000000000000[{#}\N{U+0.00}0000/', # [perl #134059]
352 '/\p{nv=\b5\b}/' => 'Can\'t find Unicode property definition "nv=\\b5\\b" {#} m/\\p{nv=\\b5\\b}{#}/',
353 '/\p{nv=:(?g)10:}/' => 'Use of modifier \'g\' is not allowed in Unicode property wildcard subpatterns {#} m/(?g{#})10/',
354 '/\p{gc=:L*:}/' => 'Use of quantifier \'*\' is not allowed in Unicode property wildcard subpatterns {#} m/L*{#}/',
355 '/\p{gc=:L\G:}/' => 'Use of \'\G\' is not allowed in Unicode property wildcard subpatterns {#} m/L\G{#}/',
356 '/\p{gc=:(?a)L:}/' => 'Use of modifier \'a\' is not allowed in Unicode property wildcard subpatterns {#} m/(?a){#}L/',
357 '/\p{gc=:(?u)L:}/' => 'Use of modifier \'u\' is not allowed in Unicode property wildcard subpatterns {#} m/(?u){#}L/',
358 '/\p{gc=:(?d)L:}/' => 'Use of modifier \'d\' is not allowed in Unicode property wildcard subpatterns {#} m/(?d){#}L/',
359 '/\p{gc=:(?l)L:}/' => 'Use of modifier \'l\' is not allowed in Unicode property wildcard subpatterns {#} m/(?l){#}L/',
360 '/\p{gc=:(?-m)L:}/' => 'Use of modifier \'-m\' is not allowed in Unicode property wildcard subpatterns {#} m/(?-m{#})L/',
361 '/\p{gc=:\pS:}/' => 'Use of \'\\pS\' is not allowed in Unicode property wildcard subpatterns {#} m/\\pS{#}/',
362 '/\p{gc=:\PS:}/' => 'Use of \'\\PS\' is not allowed in Unicode property wildcard subpatterns {#} m/\\PS{#}/',
363 '/\p{gc=:[\pS]:}/' => 'Use of \'\\pS\' is not allowed in Unicode property wildcard subpatterns {#} m/[\\pS{#}]/',
364 '/\p{gc=:[\PS]:}/' => 'Use of \'\\PS\' is not allowed in Unicode property wildcard subpatterns {#} m/[\\PS{#}]/',
365 '/(?[\p{name=KATAKANA LETTER AINU P}])/' => 'Unicode string properties are not implemented in (?[...]) {#} m/(?[\p{name=KATAKANA LETTER AINU P}{#}])/',
366 '/(?[ (?^x:(?[ ])) ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ (?^x:(?[ {#}])) ])/',
367 '/(?[ (?x:(?[ ])) ])/'  => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ (?x:(?[ {#}])) ])/', # GH #16779
368);
369
370# These are messages that are death under 'use re "strict"', and may or may
371# not warn otherwise.  See comment before @warning as to why some have a
372# \x{100} in them.  This array has 3 elements per construct.  [0] is the regex
373# to use; [1] is the message under no strict (empty to not warn), and [2] is
374# under strict.
375my @death_only_under_strict = (
376    'm/\xABC/' => "",
377               => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/',
378    'm/[\xABC]/' => "",
379                 => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/',
380
381    # some messages below aren't all category 'regexp'.  (Hence we have to
382    # turn off 'digit' messages as well below)
383    'm/\xAG/' => 'Non-hex character \'G\' terminates \x early.  Resolved as "\x0AG" {#} m/\xA{#}G/',
384              => 'Non-hex character {#} m/\xAG{#}/',
385    'm/[\xAG]/' => 'Non-hex character \'G\' terminates \x early.  Resolved as "\x0AG" {#} m/[\xA{#}G]/',
386                => 'Non-hex character {#} m/[\xAG{#}]/',
387    'm/\o{789}/' => 'Non-octal character \'8\' terminates \o early.  Resolved as "\o{007}" {#} m/\o{789}{#}/',
388                 => 'Non-octal character {#} m/\o{78{#}9}/',
389    'm/[\o{789}]/' => 'Non-octal character \'8\' terminates \o early.  Resolved as "\o{007}" {#} m/[\o{789}{#}]/',
390                   => 'Non-octal character {#} m/[\o{78{#}9}]/',
391    'm/\x{}/' => "",
392              => 'Empty \x{} {#} m/\x{}{#}/',
393    'm/[\x{}]/' => "",
394                => 'Empty \x{} {#} m/[\x{}{#}]/',
395    'm/\x{ABCDEFG}/' => 'Non-hex character \'G\' terminates \x early.  Resolved as "\x{ABCDEF}" {#} m/\x{ABCDEFG}{#}/',
396                     => 'Non-hex character {#} m/\x{ABCDEFG{#}}/',
397    'm/[\x{ABCDEFG}]/' => 'Non-hex character \'G\' terminates \x early.  Resolved as "\x{ABCDEF}" {#} m/[\x{ABCDEFG}{#}]/',
398                       => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/',
399    "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/',
400                       => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/',
401    'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
402                       => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
403    'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
404                       => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
405    'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
406                        => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
407    'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
408                        => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
409    '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}{#}]/',
410                                       => '\N{} here is restricted to one character {#} m/[^\N{U+100.300{#}}]/',
411    '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}{#}]/',
412                                            => '\N{} here is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/',
413    '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}]/',
414                                                  => '\N{} here is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/',
415    '/[\08]/'   => 'Non-octal character \'8\' terminates \0 early.  Resolved as "\0008" {#} m/[\08{#}]/',
416                => 'Need exactly 3 octal digits {#} m/[\08{#}]/',
417    '/[\018]/'  => 'Non-octal character \'8\' terminates \0 early.  Resolved as "\0018" {#} m/[\018{#}]/',
418                => 'Need exactly 3 octal digits {#} m/[\018{#}]/',
419    '/[\_\0]/'  => "",
420                => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/',
421    '/[\07]/'   => "",
422                => 'Need exactly 3 octal digits {#} m/[\07]{#}/',
423    '/[\0005]/' => "",
424                => 'Need exactly 3 octal digits {#} m/[\0005]{#}/',
425    '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/',
426                          'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/',
427                         ],
428                      => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/',
429    '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
430                      => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
431    '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
432                      => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
433    '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
434                       => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
435    '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
436                       => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
437    '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
438                             => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
439    '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
440                             => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
441    '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
442                                     => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
443    '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
444                                     => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
445    '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/',
446                      => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/',
447    '/[ab]/'          => "",
448                        => 'Literal vertical space in [] is illegal except under /x {#} m/[a{#}b]/',
449    '/:{4,a}/'     => 'Unescaped left brace in regex is passed through {#} m/:{{#}4,a}/',
450                   => 'Unescaped left brace in regex is illegal here {#} m/:{{#}4,a}/',
451    '/xa{3\,4}y/'  => 'Unescaped left brace in regex is passed through {#} m/xa{{#}3\,4}y/',
452                   => 'Unescaped left brace in regex is illegal here {#} m/xa{{#}3\,4}y/',
453    '/\\${[^\\}]*}/' => 'Unescaped left brace in regex is passed through {#} m/\\${{#}[^\\}]*}/',
454                     => 'Unescaped left brace in regex is illegal here {#} m/\\${{#}[^\\}]*}/',
455    '/.{/'         => 'Unescaped left brace in regex is passed through {#} m/.{{#}/',
456                   => 'Unescaped left brace in regex is illegal here {#} m/.{{#}/',
457    '/[x]{/'       => 'Unescaped left brace in regex is passed through {#} m/[x]{{#}/',
458                   => 'Unescaped left brace in regex is illegal here {#} m/[x]{{#}/',
459    '/\p{Latin}{/' => 'Unescaped left brace in regex is passed through {#} m/\p{Latin}{{#}/',
460                   => 'Unescaped left brace in regex is illegal here {#} m/\p{Latin}{{#}/',
461    '/\x{100}\x/'  => "",
462                   => "Empty \\x {#} m/\\x{100}\\x{#}/",
463    '/\o{ 1 20 }/' => 'Non-octal character \' \' terminates \o early.  Resolved as "\o{001}" {#} m/\o{ 1 20 }{#}/',
464                   => 'Non-octal character {#} m/\\o{ 1 {#}20 }/',
465    '/\x{ 5 0 }/'  => 'Non-hex character \' \' terminates \x early.  Resolved as "\x{05}" {#} m/\x{ 5 0 }{#}/',
466                   => 'Non-hex character {#} m/\\x{ 5 {#}0 }/',
467);
468
469# These need the character 'ネ' as a marker for mark_as_utf8()
470my @death_utf8 = mark_as_utf8(
471 '/ネ(?<= .*)/' =>  'Lookbehind longer than 255 not implemented in regex m/ネ(?<= .*)/',
472
473 '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/',
474
475 '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/',
476
477 '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/',
478
479 '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/',
480
481 '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/',
482
483 '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/',
484
485 '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/',
486 '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/',
487 '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/',
488 '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/',
489'/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/',
490'/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/',
491'/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/',
492
493 '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/',
494
495 "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{$inf_p1\{#}}ネ/",
496 "/ネ{$inf_p1,}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{$inf_p1\{#},}ネ/",
497 "/ネ{01}ネ/" => "Invalid quantifier in {,} {#} m/ネ{01{#}}ネ/",
498 "/ネ{1,02}ネ/" => "Invalid quantifier in {,} {#} m/ネ{1,02{#}}ネ/",
499
500
501 '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/',
502
503 '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/',
504
505 '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/',
506
507 '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/',
508
509 '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/',
510
511 '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/',
512
513 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/',
514
515 '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/',
516 '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/',
517 '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/',
518
519 '/ネ\o{ネ/' => 'Missing right brace on \o{} {#} m/ネ\o{{#}ネ/',
520
521 '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/',
522
523 '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/',
524
525 '/ネ(?[[[:ネ]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[:ネ]]{#}])ネ/",
526 '/ネ(?[[[:ネ: ])ネ/' => "Syntax error in (?[...]) {#} m/ネ(?[[[:ネ: ])ネ{#}/",
527 '/ネ(?[[[::]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[::]]{#}])ネ/",
528 '/ネ(?[[[:ネ:]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[:ネ:]]{#}])ネ/",
529 '/ネ(?[ネ])ネ/' =>  'Unexpected character {#} m/ネ(?[ネ{#}])ネ/',
530 '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/',
531 '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/',
532 '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/',
533 '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/',
534 '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/',
535 '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/',
536 '/ネ(?[ \o{} ])ネ/' => 'Empty \o{} {#} m/ネ(?[ \o{}{#} ])ネ/',
537 '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/',
538 '/(?[ \p{ネ} ])/' => 'Can\'t find Unicode property definition "ネ" {#} m/(?[ \p{ネ}{#} ])/',
539 '/(?[ \p{ ネ = bar } ])/' => 'Can\'t find Unicode property definition "ネ = bar" {#} m/(?[ \p{ ネ = bar }{#} ])/',
540 '/ネ(?[ \t ]/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[ \\t ]{#}/",
541 '/(?[ \t + \e # ネ This was supposed to be a comment ])/' =>
542    "Syntax error in (?[...]) {#} m/(?[ \\t + \\e # ネ This was supposed to be a comment ]){#}/",
543 'm/(*ネ)ネ/' => q<Unknown '(*...)' construct 'ネ' {#} m/(*ネ){#}ネ/>,
544 '/\cネ/' => "Character following \"\\c\" must be printable ASCII {#} m/\\cネ{#}/",
545 '/[\cネ]/' => "Character following \"\\c\" must be printable ASCII {#} m/[\\cネ{#}]/",
546 '/\b{ネ}/' => "'ネ' is an unknown bound type {#} m/\\b{ネ{#}}/",
547 '/\B{ネ}/' => "'ネ' is an unknown bound type {#} m/\\B{ネ{#}}/",
548);
549push @death, @death_utf8;
550
551my @death_utf8_only_under_strict = (
552    "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/',
553                   => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/',
554    'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
555                     => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
556    'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
557                     => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
558    'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
559                      => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
560    '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
561                           => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
562    '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
563                    => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
564    '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/',
565                   => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/',
566);
567# Tests involving a user-defined charnames translator are in pat_advanced.t
568
569# In the following arrays of warnings, the value can be an array of things to
570# expect.  If the empty string, it means no warning should be raised.
571
572
573# Key-value pairs of code/error of code that should have non-fatal regexp
574# warnings.  Most currently have \x{100} appended to them to force them to be
575# upgraded to UTF-8, and the first pass restarted.  Previously this would
576# cause some warnings to be output twice.  This tests that that behavior has
577# been fixed.
578
579my @warning = (
580    'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
581    '/\b{g}/a' => "Using /u for '\\b{g}' instead of /a {#} m/\\b{g}{#}/",
582    '/\B{gcb}/a' => "Using /u for '\\B{gcb}' instead of /a {#} m/\\B{gcb}{#}/",
583    'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
584    'm/[[:cntrl:]][:^ascii:]\x{100}/' =>  'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/',
585    'm/[[:ascii]]\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/[[:ascii{#}]]\\x{100}/",
586    'm/(?[[:word]])\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/(?[[:word{#}]])\\x{100}/",
587    "m'\\y\\x{100}'"     => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
588    '/x{3,1}/'   => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
589    '/\08/' => 'Non-octal character \'8\' terminates \0 early.  Resolved as "\0008" {#} m/\08{#}/',
590
591    '/\018/' => 'Non-octal character \'8\' terminates \0 early.  Resolved as "\0018" {#} m/\018{#}/',
592    '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
593    'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
594    '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
595    '/\q\p{Any}/' => 'Unrecognized escape \q passed through {#} m/\q{#}\p{Any}/',
596
597    # These two tests do not include the marker, because regcomp.c no
598    # longer knows where it goes by the time this warning is emitted.
599    # See [perl #122680] regcomp warning gives wrong position of
600    # problem.
601    '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/',
602    '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/',
603
604    '/\_/' => "",
605    '/[\006]/' => "",
606    '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/',
607    '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:zog:]{#}\x{100}/',
608    '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes (but this one isn\'t implemented) {#} m/[.zog.]{#}\x{100}/',
609    '/[a-b]/' => "",
610    '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/',
611    '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/',
612    '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/',
613    '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/',
614    '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/',
615    '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/',
616    '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/',
617                    'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/',
618                  ],
619    '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/',
620                    'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/',
621                  ],
622      # (?c) means (?g) error won't be thrown
623     '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/',
624                      'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/',
625                    ],
626    '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/',
627                    'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/',
628                    'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/',
629                  ],
630    '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/',
631    "/(?[ [ % - % ] ])/" => "",
632    "/(?[ [ : - \\x$colon_hex ] ])\\x{100}/" => "\": - \\x$colon_hex \" is more clearly written simply as \":\" {#} m/(?[ [ : - \\x$colon_hex {#}] ])\\x{100}/",
633    "/(?[ [ \\x$colon_hex - : ] ])\\x{100}/" => "\"\\x$colon_hex\ - : \" is more clearly written simply as \":\" {#} m/(?[ [ \\x$colon_hex - : {#}] ])\\x{100}/",
634    "/(?[ [ \\t - \\x$tab_hex ] ])\\x{100}/" => "\"\\t - \\x$tab_hex \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\t - \\x$tab_hex {#}] ])\\x{100}/",
635    "/(?[ [ \\x$tab_hex - \\t ] ])\\x{100}/" => "\"\\x$tab_hex\ - \\t \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\x$tab_hex - \\t {#}] ])\\x{100}/",
636    "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/",
637    "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/",
638    "/(?[ [ $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 {#}] ])/",
639    "/(?[ [ $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 {#}] ])/",
640    "/[alnum]/" => "",
641    "/[^alnum]/" => "",
642    '/[:blank]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:blank{#}]\x{100}/',
643    '/[[:digit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:digit{#}]]\x{100}/', # [perl # 8904]
644    '/[[:digit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:digit:{#}foo]\x{100}/',
645    '/[[:di#it:foo]\x{100}/x' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:di#it:{#}foo]\x{100}/',
646    '/[[:dgit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:dgit{#}]]\x{100}/',
647    '/[[:dgit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:dgit:{#}foo]\x{100}/',
648    '/[[:dgt]]\x{100}/' => "",      # Far enough away from a real class to not be recognized as one
649    '/[[:dgt:foo]\x{100}/' => "",
650    '/[[:DIGIT]]\x{100}/' => [ 'Assuming NOT a POSIX class since the name must be all lowercase letters {#} m/[[:DIGIT{#}]]\x{100}/',
651                               'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:DIGIT{#}]]\x{100}/',
652                           ],
653    '/[[digit]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}digit]\x{100}/',
654                             'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[digit{#}]\x{100}/',
655                           ],
656    '/[[alpha]]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}alpha]]\x{100}/',
657                              'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[alpha{#}]]\x{100}/',
658                           ],
659    '/[[^word]\x{100}/' => [ 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[^{#}word]\x{100}/',
660                              'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[^{#}word]\x{100}/',
661                              'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[^word{#}]\x{100}/',
662                            ],
663    '/[[   ^   :   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}/',
664                                               'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[   ^{#}   :   x d i g i t   :   ]   ]\x{100}/',
665                                               'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   {#}:   x d i g i t   :   ]   ]\x{100}/',
666                                               'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   :   {#}x d i g i t   :   ]   ]\x{100}/',
667                                               'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[   ^   :   x d i g i t   :   ]{#}   ]\x{100}/',
668                                               $only_strict_marker . 'Unescaped literal \']\' {#} m/[[   ^   :   x d i g i t   :   ]   ]{#}\x{100}/',
669                            ],
670    '/[foo:lower:]]\x{100}/' => 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#}:lower:]]\x{100}/',
671    '/[[;upper;]]\x{100}/' => [ 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;{#}upper;]]\x{100}/',
672                                'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;upper;]{#}]\x{100}/',
673                              ],
674    '/[foo;punct;]]\x{100}/' => [ 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#};punct;]]\x{100}/',
675                                  'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;{#}punct;]]\x{100}/',
676                                  'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;punct;]{#}]\x{100}/',
677                                ],
678   '/[][[:alpha:]]/' => "",        # [perl #127581]
679   '/[][[:alpha:]\\@\\\\^_?]/' => "", # [perl #131522]
680    '/(?[[:w:]])/' => "",
681    '/([.].*)[.]/'   => "",    # [perl #127582]
682    '/[.].*[.]/'     => "",    # [perl #127604]
683    '/abc/xix' => "",
684    '/(?xmsixp:abc)/' => "",
685    '/(?xmsixp)abc/' => "",
686    '/(?xxxx:abc)/' => "",
687
688); # See comments before this for why '\x{100}' is generally needed
689
690# These need the character 'ネ' as a marker for mark_as_utf8()
691my @warnings_utf8 = mark_as_utf8(
692    'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/',
693    '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/',
694    'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/ネ[:foo:]{#}ネ/',
695    '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/',
696    '/utf8 ネ (?ogc) ネ/' => [
697        'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/',
698        'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/',
699        'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/',
700    ],
701   '/ネ[[:ネ:]]ネ/' => "",
702   '/ネ(?[[:ネ:]])ネ/' => "",
703
704);
705
706push @warning, @warnings_utf8;
707
708my @warning_only_under_strict = (
709    '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/',
710    '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/',
711    '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/',
712    '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/',
713    '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/',
714    '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/',
715    '/[\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}/',
716    '/[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}/',
717    '/[\N{U+00}-\a]\x{100}/' => "",
718    '/[\a-\N{U+FF}]\x{100}/' => "",
719    '/[\N{U+100}-\x{101}]/' => "",
720    "/[%-%]/" => "",
721    "/[:-\\x$colon_hex]\\x{100}/" => "\":-\\x$colon_hex\" is more clearly written simply as \":\" {#} m/[:-\\x$colon_hex\{#}]\\x{100}/",
722    "/[\\x$colon_hex-:]\\x{100}/" => "\"\\x$colon_hex-:\" is more clearly written simply as \":\" {#} m/[\\x$colon_hex\-:{#}]\\x{100}/",
723    "/[\\t-\\x$tab_hex]\\x{100}/" => "\"\\t-\\x$tab_hex\" is more clearly written simply as \"\\t\" {#} m/[\\t-\\x$tab_hex\{#}]\\x{100}/",
724    "/[\\x$tab_hex-\\t]\\x{100}/" => "\"\\x$tab_hex-\\t\" is more clearly written simply as \"\\t\" {#} m/[\\x$tab_hex\-\\t{#}]\\x{100}/",
725    "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/",
726    "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/",
727    "/[$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\{#}]/",
728    "/[$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\{#}]/",
729    '/\b<GCB}/' => 'Unescaped literal \'}\' {#} m/\b<GCB}{#}/',
730    '/[ ]def]/' => 'Unescaped literal \']\' {#} m/[ ]def]{#}/',
731    '/(?)/' => 'Empty (?) without any modifiers {#} m/(?){#}/', # [perl #132851]
732);
733
734my @warning_utf8_only_under_strict = mark_as_utf8(
735 '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/",
736 '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/",
737 '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/",
738 '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/",
739 '/ネ(?[ [ �� - �� ] ])/; #no latin1' => "",
740 '/ネ(?[ [ �� - �� ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ �� - �� {#}] ])/",
741 '/ネ(?[ [ �� - �� ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ �� - �� {#}] ])/",
742);
743
744push @warning_only_under_strict, @warning_utf8_only_under_strict;
745
746my @experimental_vlb = (
747    '/(?<=(p|qq|rrr))/' => 'Variable length positive lookbehind with capturing' .
748                           ' is experimental {#} m/(?<=(p|qq|rrr)){#}/',
749    '/(?<!(p|qq|rrr))/' => 'Variable length negative lookbehind with capturing' .
750                           ' is experimental {#} m/(?<!(p|qq|rrr)){#}/',
751    '/(?| (?=(foo)) | (?<=(foo)|p) )/'
752            => 'Variable length positive lookbehind with capturing' .
753               ' is experimental {#} m/(?| (?=(foo)) | (?<=(foo)|p) ){#}/',
754    '/(?| (?=(foo)) | (?<=(foo)|p) )/x'
755            => 'Variable length positive lookbehind with capturing' .
756               ' is experimental {#} m/(?| (?=(foo)) | (?<=(foo)|p) ){#}/',
757    '/(?| (?=(foo)) | (?<!(foo)|p) )/'
758            => 'Variable length negative lookbehind with capturing' .
759               ' is experimental {#} m/(?| (?=(foo)) | (?<!(foo)|p) ){#}/',
760    '/(?| (?=(foo)) | (?<!(foo)|p) )/x'
761            => 'Variable length negative lookbehind with capturing' .
762               ' is experimental {#} m/(?| (?=(foo)) | (?<!(foo)|p) ){#}/',
763    '/(?<!(foo|bop(*ACCEPT)|bar)baz)/'
764            => 'Variable length negative lookbehind with capturing' .
765               ' is experimental {#} m/(?<!(foo|bop(*ACCEPT)|bar)baz){#}/',
766    '/(?<=(foo|bop(*ACCEPT)|bar)baz)/'
767            => 'Variable length positive lookbehind with capturing' .
768               ' is experimental {#} m/(?<=(foo|bop(*ACCEPT)|bar)baz){#}/',
769);
770
771my @wildcard = (
772    'm!(?[\p{name=/KATAKANA/}])$!' =>
773    [
774     'The Unicode property wildcards feature is experimental',
775     'Using just the single character results returned by \p{} in (?[...]) {#} m/(?[\p{name=/KATAKANA/}{#}])$/'
776    ], # [GH #17732] Null pointer deref
777);
778
779my @deprecated = (
780 '/^{/'          => "",
781 '/foo|{/'       => "",
782 '/foo|^{/'      => "",
783 '/foo(:?{bar)/' => "",
784 '/\s*{/'        => "",
785 '/a{3,4}{/'     => "",
786);
787
788for my $strict ("", "use re 'strict';") {
789
790    # First time just use @death; but under strict we add the things that fail
791    # there.  Doing it this way makes sure that 'strict' doesnt change the
792    # things that are already fatal when not under strict.
793    if ($strict) {
794        for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
795            push @death, $death_only_under_strict[$i],    # The regex
796                         $death_only_under_strict[$i+2];  # The fatal msg
797        }
798        for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
799
800            # Same with the utf8 versions
801            push @death, mark_as_utf8($death_utf8_only_under_strict[$i],
802                                      $death_utf8_only_under_strict[$i+2]);
803        }
804    }
805    for (my $i = 0; $i < @death; $i += 2) {
806        my $regex = $death[$i] =~ s/ default_ (on | off) //rx;
807        my $expect = fixup_expect($death[$i+1], $strict);
808        if ($expect eq "") {
809            fail("$0: Internal error: '$death[$i]' should have an error message");
810        }
811        else {
812            no warnings 'experimental::re_strict';
813            no warnings 'experimental::uniprop_wildcards';
814
815            warning_is(sub {
816                    my $meaning_of_life;
817                    my $eval_string = "$strict $regex";
818                    $_ = "x";
819                    eval "$eval_string; \$meaning_of_life = 42";
820                    ok(! defined $meaning_of_life, display_rx("$eval_string died"));
821                    my $error= $@;
822                    if ($error =~ qr/\Q$expect/) {
823                        ok(1, "... and gave expected message");
824                    } else {
825                        ok(0, display_rx($eval_string));
826                        diag("Have: " . display_rx(add_markers($error)));
827                        diag("Want: " . display_rx($death[$i+1]));
828                    }
829                }, undef, "... and no other warnings");
830        }
831    }
832}
833
834for my $strict ("",  "no warnings 'experimental::re_strict'; use re 'strict';") {
835    my @warning_tests = @warning;
836
837    # Build the tests for @warning.  Use the strict/non-strict versions
838    # appropriately.
839    if ($strict) {
840        push @warning_tests, @warning_only_under_strict;
841    }
842    else {
843        for (my $i = 0; $i < @warning_only_under_strict; $i += 2) {
844
845            # (?[ ]) are always under strict
846            if ($warning_only_under_strict[$i] =~ /\Q(?[/) {
847                push @warning_tests, $warning_only_under_strict[$i],  # The regex
848                                    $warning_only_under_strict[$i+1];
849            }
850            else {
851                push @warning_tests, $warning_only_under_strict[$i],  # The regex
852                                    "";    # No warning because not strict
853            }
854        }
855        for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
856            push @warning_tests, $death_only_under_strict[$i],    # The regex
857                                 $death_only_under_strict[$i+1];  # The warning
858        }
859        for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
860            push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i],
861                                        $death_utf8_only_under_strict[$i+1]);
862        }
863    }
864
865    foreach my $ref (
866        \@warning_tests,
867        \@wildcard,
868        \@deprecated,
869        \@experimental_vlb,
870    ){
871        my $warning_type;
872        my $default_on;
873        if ($ref == \@warning_tests) {
874            $warning_type = 'regexp, digit';
875            $default_on = $strict;
876        }
877        elsif ($ref == \@deprecated) {
878            $warning_type = 'regexp, deprecated';
879            $default_on = 1;
880        }
881        elsif ($ref == \@wildcard) {
882            $warning_type = 'experimental::uniprop_wildcards';
883            $default_on = 1;
884        }
885        elsif ($ref == \@experimental_vlb) {
886            $warning_type = 'experimental::vlb';
887            $default_on = 1;
888        }
889        else {
890            fail("$0: Internal error: Unexpected loop variable");
891        }
892
893        for (my $i = 0; $i < @$ref; $i += 2) {
894            my $this_default_on = $default_on;
895            my $regex = $ref->[$i];
896            if ($regex =~ s/ default_ (on | off) //x) {
897                $this_default_on = $1 eq 'on';
898            }
899            my @expect = fixup_expect($ref->[$i+1], $strict);
900
901            # A length-1 array with an empty warning means no warning gets
902            # generated at all.
903            undef @expect if @expect == 1 && $expect[0] eq "";
904
905            {
906                $_ = "x";
907                #use feature 'unicode_eval';
908                #print STDERR __LINE__, ": ", "eval '$strict no warnings; $regex'", "\n";
909                eval "$strict no warnings; $regex";
910            }
911            my $display = display_rx($regex); # used in the test names.
912            if (is($@, "", "$strict $display did not die")) {
913                my @got = capture_warnings(sub {
914                                        $_ = "x";
915                                        eval "$strict $regex" });
916                my $count = @expect;
917                if (! is(scalar @got, scalar @expect,
918                            "... and gave expected number ($count) of warnings"))
919                {
920                    if (@got < @expect) {
921                        $count = @got;
922                        note display_rx("Expected warnings not gotten:\n\t"
923                                        . join("\n\t", @expect[$count .. $#expect]));
924                    }
925                    else {
926                        note display_rx("Unexpected warnings gotten:\n\t"
927                                        . join("\n\t", @got[$count .. $#got]));
928                    }
929                }
930                foreach my $i (0 .. $count - 1) {
931                    if (! like($got[$i], qr/\Q$expect[$i]/,
932                                               "... and gave expected warning"))
933                    {
934                        chomp($got[$i]);
935                        chomp($expect[$i]);
936                        diag(display_rx("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'"));
937                    }
938                    else {
939                            # Turning off this type of warning should make the
940                            # count go down by at least 1.
941                        ok ($count - 1 >= capture_warnings(sub {
942                            $_ = "x";
943                            eval "$strict no warnings '$warning_type'; $regex;" }
944                           ),
945                           "... and turning off '$warning_type' warnings suppressed it");
946
947                        # Test that whether the warning is on by default is
948                        # correct.  This test relies on the fact that we
949                        # are outside the scope of any ‘use warnings’.
950                        local $^W;
951                        my @warns = capture_warnings(sub {
952                                            $_ = "x";
953                                            eval "$strict $regex"
954                                            });
955                        # Warning should be on as well if is testing
956                        # '(?[...])' which turns on strict
957                        if (   $this_default_on
958                            || (    grep { $_ =~ /\Q(?[/ } @expect
959                                and $ref != \@warning_tests))
960                        {
961                           ok @warns > 0, "... and the warning is on by default";
962                        }
963                        elsif (! (ok @warns == 0,
964                                     "... and the warning is off by default"))
965                        {
966                               diag(display_rx("GOT\n" . join "\n", @warns));
967                        }
968                    }
969                }
970            }
971        }
972    }
973}
974
975done_testing();
976