From: Father Chrysostomos Date: Wed, 22 Oct 2014 19:57:11 +0000 (-0700) Subject: [perl #122680] Omit <-- HERE marker from (?=){3} warning X-Git-Tag: v5.21.6~434 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/e1729dc6ad52e1bd43f51e7f3a1dd66938ef9153?hp=cb4ea3e667c17d04aceb8aa99c7314653561f238 [perl #122680] Omit <-- HERE marker from (?=){3} warning ‘Quantifier unexpected on zero-length expression’ was always putting the marker at the end of the regular expression, instead of where it actually goes. --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index fbfdb93..3cc009a 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -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, not C. -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 ".." diff --git a/regcomp.c b/regcomp.c index a62e3e1..6853d76 100644 --- 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); } diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t index 126a427..e61e8ef 100644 --- a/t/re/reg_mesg.t +++ b/t/re/reg_mesg.t @@ -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]/' => "",