From: Mark-Jason Dominus Date: Thu, 28 Mar 2002 05:04:40 +0000 (-0500) Subject: warning at use of /c modifier without /g modifier X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ac733c9bd1b714b72e7aa46038b74060cad7c98;p=p5sagit%2Fp5-mst-13.2.git warning at use of /c modifier without /g modifier Message-ID: <20020328100440.22081.qmail@plover.com> p4raw-id: //depot/perl@15579 --- diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 1323772..b9e9936 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -555,6 +555,11 @@ the angle bracket operator. The command-line options -s and -F are now recognized on the shebang (#!) line. +=item * + +Use of the C match modifier without an accompanying C modifier +elicits a new warning: C. + =back =head1 Modules and Pragmata diff --git a/pod/perldiag.pod b/pod/perldiag.pod index d140b0a..3b3a71f 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3983,6 +3983,12 @@ returns no useful value. See L. (D deprecated) You are now encouraged to use the explicitly quoted form if you wish to use an empty line as the terminator of the here-document. +=item Use of /c modifier is meaningless without /g + +(W regexp) You used the /c modifier with a regex operand, but didn't +use the /g modifier. Currently, /c is meaningful only when /g is +used. (This may change in the future.) + =item Use of *glob{FILEHANDLE} is deprecated (D deprecated) You are now encouraged to use the shorter *glob{IO} form diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index 01e31f8..af67277a 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -103,7 +103,9 @@ toke.c AOK $a = 0047777777777 ; dump() better written as CORE::dump() - + + Use of /c modifier is meaningless without /g + Mandatory Warnings ------------------ Use of "%s" without parentheses is ambiguous [check_uni] @@ -738,3 +740,22 @@ no warnings 'misc'; "bar" =~ /\_/; EXPECT Unrecognized escape \q passed through at - line 4. +######## +# toke.c +# 20020328 mjd@plover.com at behest of jfriedl@yahoo.com +use warnings 'regexp'; +"foo" =~ /foo/c; +no warnings 'regexp'; +"foo" =~ /foo/c; +EXPECT +Use of /c modifier is meaningless without /g at - line 4. +######## +# toke.c +# 20020328 mjd@plover.com at behest of jfriedl@yahoo.com +use warnings 'regexp'; +$_ = "ab" ; +s/ab/ab/c; +no warnings 'regexp'; +s/ab/ab/c; +EXPECT +Use of /c modifier is meaningless without /g at - line 5. diff --git a/toke.c b/toke.c index 85ec1d1..7bc7661 100644 --- a/toke.c +++ b/toke.c @@ -26,6 +26,7 @@ #define yylval PL_yylval static char ident_too_long[] = "Identifier too long"; +static char c_without_g[] = "Use of /c modifier is meaningless without /g"; static void restore_rsfp(pTHX_ void *f); #ifndef PERL_NO_UTF16_FILTER @@ -6284,6 +6285,13 @@ S_scan_pat(pTHX_ char *start, I32 type) while (*s && strchr("iogcmsx", *s)) pmflag(&pm->op_pmflags,*s++); } + /* issue a warning if /c is specified,but /g is not */ + if (ckWARN(WARN_REGEXP) && + (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) + { + Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); + } + pm->op_pmpermflags = pm->op_pmflags; PL_lex_op = (OP*)pm; @@ -6332,6 +6340,13 @@ S_scan_subst(pTHX_ char *start) break; } + /* issue a warning if /c is specified,but /g is not */ + if (ckWARN(WARN_REGEXP) && + (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) + { + Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); + } + if (es) { SV *repl; PL_sublex_info.super_bufptr = s;