This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add deprecation warning for my $x if 0
authorDave Mitchell <davem@fdisolutions.com>
Thu, 4 Mar 2004 21:39:47 +0000 (21:39 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Thu, 4 Mar 2004 21:39:47 +0000 (21:39 +0000)
p4raw-id: //depot/perl@22435

op.c
t/lib/warnings/op

diff --git a/op.c b/op.c
index c8a74fd..ca24417 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3369,6 +3369,23 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
            return other;
        }
        else {
+           /* check for C<my $x if 0>, or C<my($x,$y) if 0> */
+           OP *o2 = other;
+           if ( ! (o2->op_type == OP_LIST
+                   && (( o2 = cUNOPx(o2)->op_first))
+                   && o2->op_type == OP_PUSHMARK
+                   && (( o2 = o2->op_sibling)) )
+           )
+               o2 = other;
+           if ((o2->op_type == OP_PADSV || o2->op_type == OP_PADAV
+                       || o2->op_type == OP_PADHV)
+               && o2->op_private & OPpLVAL_INTRO
+               && ckWARN(WARN_DEPRECATED))
+           {
+               Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
+                           "Deprecated use of my() in false conditional");
+           }
+
            op_free(other);
            *otherp = Nullop;
            first->op_private |= OPpCONST_SHORTCIRCUIT;
index 95f3fc8..c39a7b2 100644 (file)
@@ -1053,3 +1053,28 @@ Useless localization of defined or assignment (//=) at - line 45.
 Useless localization of substr at - line 48.
 Useless localization of match position at - line 49.
 Useless localization of vec at - line 50.
+########
+# op.c
+use warnings 'deprecated';
+my $x1 if 0;
+my @x2 if 0;
+my %x3 if 0;
+my ($x4) if 0;
+my ($x5,@x6, %x7) if 0;
+0 && my $z1;
+0 && my (%z2);
+# these shouldn't warn
+our $x if 0;
+our $x unless 0;
+if (0) { my $w1 }
+if (my $w2) { $a=1 }
+if ($a && (my $w3 = 1)) {$a = 2}
+
+EXPECT
+Deprecated use of my() in false conditional at - line 3.
+Deprecated use of my() in false conditional at - line 4.
+Deprecated use of my() in false conditional at - line 5.
+Deprecated use of my() in false conditional at - line 6.
+Deprecated use of my() in false conditional at - line 7.
+Deprecated use of my() in false conditional at - line 8.
+Deprecated use of my() in false conditional at - line 9.