Eliminate ‘Can't use \1 to mean $1’ false positives
authorFather Chrysostomos <sprout@cpan.org>
Wed, 30 Oct 2013 13:18:20 +0000 (06:18 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 30 Oct 2013 23:54:17 +0000 (16:54 -0700)
We need to check that the quote-like operator we are parsing is a sub-
stitution (not just any quote-like operator) and that we are parsing
the right-hand side.

t/lib/warnings/toke
toke.c

index eb918f1..02c6ccc 100644 (file)
@@ -304,6 +304,9 @@ You need to quote "ふれど" at - line 5.
 use warnings 'syntax' ;
 $_ = "ab" ; 
 s/(ab)/\1/e;
+s//\(2)/e; # should be exempt
+s/${\2}//; # same here
+()="${\2}"; # metoo
 no warnings 'syntax' ;
 $_ = "ab" ; 
 s/(ab)/\1/e;
diff --git a/toke.c b/toke.c
index 2ed27a9..4ba35ac 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -6943,7 +6943,8 @@ Perl_yylex(pTHX)
 
     case '\\':
        s++;
-       if (PL_lex_inwhat && isDIGIT(*s))
+       if (PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr
+        && isDIGIT(*s))
            Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
                           *s, *s);
        if (PL_expect == XOPERATOR)