This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #122680] Omit <-- HERE marker from (?=){3} warning
authorFather Chrysostomos <sprout@cpan.org>
Wed, 22 Oct 2014 19:57:11 +0000 (12:57 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 22 Oct 2014 19:57:38 +0000 (12:57 -0700)
‘Quantifier unexpected on zero-length expression’ was always putting
the marker at the end of the regular expression, instead of where
it actually goes.

pod/perldiag.pod
regcomp.c
t/re/reg_mesg.t

index fbfdb93..3cc009a 100644 (file)
@@ -4714,8 +4714,7 @@ S<<-- HERE> in m/%s/
 (W regexp) Minima should be less than or equal to maxima.  If you really
 want your regexp to match something 0 times, just put {0}.
 
-=item Quantifier unexpected on zero-length expression in regex; marked by <-- 
-HERE in m/%s/
+=item Quantifier unexpected on zero-length expression in regex m/%s/
 
 (W regexp) You applied a regular expression quantifier in a place where
 it makes no sense, such as on a zero-width assertion.  Try putting the
@@ -4723,9 +4722,6 @@ quantifier inside the assertion instead.  For example, the way to match
 "abc" provided that it is followed by three repetitions of "xyz" is
 C</abc(?=(?:xyz){3})/>, not C</abc(?=xyz){3}/>.
 
-The <-- HERE shows whereabouts in the regular expression the problem was
-discovered.
-
 =item Range iterator outside integer range
 
 (F) One (or both) of the numeric arguments to the range operator ".."
index a62e3e1..6853d76 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -4833,8 +4833,11 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                {
                    /* Fatal warnings may leak the regexp without this: */
                    SAVEFREESV(RExC_rx_sv);
-                   ckWARNreg(RExC_parse,
-                           "Quantifier unexpected on zero-length expression");
+                   Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP),
+                       "Quantifier unexpected on zero-length expression "
+                       "in regex m/%"UTF8f"/",
+                        UTF8fARG(UTF, RExC_end - RExC_precomp,
+                                 RExC_precomp));
                    (void)ReREFCNT_inc(RExC_rx_sv);
                }
 
index 126a427..e61e8ef 100644 (file)
@@ -356,13 +356,12 @@ my @warning = (
     'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
     '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
 
-    # Feel free to modify these 2 tests, should they start failing because the
-    # marker of where the problem is becomes wrong.  The current behavior is
-    # bad, always marking at the very end of the regex instead of where the
-    # problem is.  See [perl #122680] regcomp warning gives wrong position of
+    # These two tests do not include the marker, because regcomp.c no
+    # longer knows where it goes by the time this warning is emitted.
+    # See [perl #122680] regcomp warning gives wrong position of
     # problem.
-    '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression {#} m/(?=a){1,3}\x{100}{#}/',
-    '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression {#} m/(a|b)(?=a){3}\x{100}{#}/',
+    '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/',
+    '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/',
 
     '/\_/' => "",
     '/[\_\0]/' => "",