[PATCH] warning at use of /c modifier without /g modifier

It makes no sense to use /c without /g, right?
As best I can tell, such a /c is ignored.

The appended patch creates a warning:

   % perl -w -e '"x" =~ m/foo/c'
   Use of /c modifier is meaningless without /g at -e line 1.

Jeffrey


--- bleedperl.orig/pod/perldiag.pod	Fri Mar 22 01:40:12 2002
+++ bleedperl/pod/perldiag.pod	Tue Mar 26 15:40:11 2002
@@ -3874,6 +3874,12 @@
 (W untie) A copy of the object returned from C<tie> (or C<tied>) was
 still valid when C<untie> was called.
 
+=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. Currenly, /c has meaning only when /g is used, but his may
+change in the future.
+
 =item Useless (?%s) - use /%s modifier in regex;
 
 marked by <-- HERE in m/%s/
--- bleedperl.orig/toke.c	Thu Mar 21 11:24:00 2002
+++ bleedperl/toke.c	Tue Mar 26 15:36:11 2002
@@ -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
@@ -6276,6 +6277,13 @@
 	while (*s && strchr("iogcmsx", *s))
 	    pmflag(&pm->op_pmflags,*s++);
     }
+    /* issue a warning if /c is specified,but /g is not */
+    if (ckWARN(WARN_MISC) && 
+        (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
+    {
+        Perl_warner(aTHX_ packWARN(WARN_MISC), c_without_g);
+    }
+
     pm->op_pmpermflags = pm->op_pmflags;
 
     PL_lex_op = (OP*)pm;
@@ -6322,6 +6330,13 @@
 	    pmflag(&pm->op_pmflags,*s++);
 	else
 	    break;
+    }
+
+    /* issue a warning if /c is specified,but /g is not */
+    if (ckWARN(WARN_MISC) &&
+        (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
+    {
+        Perl_warner(aTHX_ packWARN(WARN_MISC), c_without_g);
     }
 
     if (es) {
0
jfriedl
3/26/2002 11:50:36 PM
perl.perl5.porters 47795 articles. 1 followers. Follow

4 Replies
570 Views

Similar Articles

[PageSpeed] 2

Jeffrey Friedl says:
> +    if (ckWARN(WARN_MISC) && 

I think WARN_MISC is a bad idea.  As I understand it, the main point
of lexical warnings is to be able to suppress certain warnings over
certain scopes.

Since 'misc' is meaningless, there is no way for anyone to know what
warnings are included in the category, and presumably it will change
from version to version.  Suppose someone has written a program and
wants to suppress the warning "Constant subroutine redefined".  They
disable 'misc'; then they upgrade Perl, and they don't get Jeffrey's
new warning, even though it has nothing at all to do with constant
subroutines, and they might have wanted to see it.

I think 'misc' should be done away with.  It is never useful, and will
encourage people to get themselves into the same sort of trouble that
$^W got people into in the past.  If there are a bunch of categories
with only one warning each, so be it.

0
mjd
3/27/2002 12:34:26 AM
Mark-Jason Dominus <mjd@plover.com> wrote:
|> Jeffrey Friedl says:
|> > +    if (ckWARN(WARN_MISC) && 
|> 
|> I think WARN_MISC is a bad idea.

I agree -- I just wasn't sure where else to put it, so picked one that
looked vaguely reasonable.

        Jeffrey
0
jfriedl
3/27/2002 12:43:17 AM
Jeffrey Friedl <jfriedl@yahoo.com> wrote:
:The appended patch creates a warning:
:   Use of /c modifier is meaningless without /g at -e line 1.

Tests?

:+(W regexp) You used the /c modifier with a regex operand, but didn't use
:+the /g modifier. Currenly, /c has meaning only when /g is used, but his may
:+change in the future.

s/his/this/

Hugo
0
hv
3/27/2002 2:45:51 AM
On Wed, Mar 27, 2002 at 02:45:51AM +0000, Hugo van der Sanden wrote:
> Jeffrey Friedl <jfriedl@yahoo.com> wrote:
> :The appended patch creates a warning:
> :   Use of /c modifier is meaningless without /g at -e line 1.
> 
> Tests?
> 
> :+(W regexp) You used the /c modifier with a regex operand, but didn't use
> :+the /g modifier. Currenly, /c has meaning only when /g is used, but his may
> :+change in the future.
> 
> s/his/this/

Could I get a fixed fix?  I think WARN_REGEXP category would work...

> Hugo

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen
0
jhi
3/28/2002 4:54:06 AM
Reply: