From: Robin Houston Date: Mon, 2 Apr 2001 15:03:29 +0000 (+0100) Subject: Re: [ID 20010331.003] new misc warning for push(@x), unshift(@x) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=936edb8bce14c9708bc6198559047de5d7e6af47;p=p5sagit%2Fp5-mst-13.2.git Re: [ID 20010331.003] new misc warning for push(@x), unshift(@x) Message-ID: <20010402150329.A6636@puffinry.freeserve.co.uk> p4raw-id: //depot/perl@9532 --- diff --git a/op.c b/op.c index 155f107..44a19d3 100644 --- a/op.c +++ b/op.c @@ -5679,6 +5679,12 @@ Perl_ck_fun(pTHX_ OP *o) list(kid); break; case OA_AVREF: + if ((type == OP_PUSH || type == OP_UNSHIFT) + && !kid->op_sibling && ckWARN(WARN_MISC)) + Perl_warner(aTHX_ WARN_MISC, + "Useless use of %s with no arguments", + PL_op_desc[type]); + if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { diff --git a/pod/perldiag.pod b/pod/perldiag.pod index c6103c4..16b4ec2 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3949,6 +3949,15 @@ which means that Perl 5 will try to call the subroutine when the assignment is executed, which is probably not what you want. (If it IS what you want, put an & in front.) +=item Useless use of %s with no arguments + +(W misc) You used the push() or unshift() function with no arguments +apart from the array, like C or C. That won't +usually have any effect on the array, so is completely useless. It's +possible in principle that push(@tied_array) could have some effect +if the array is tied to a class which implements a PUSH method. If so, +you can write it as C to avoid this warning. + =back =cut diff --git a/t/lib/db-recno.t b/t/lib/db-recno.t index 8b5a88c..4ca547f 100755 --- a/t/lib/db-recno.t +++ b/t/lib/db-recno.t @@ -202,7 +202,7 @@ ok(30, $value eq $shifted ); # UNSHIFT # empty list -($FA ? unshift @h : $X->unshift) ; +($FA ? unshift @h,() : $X->unshift) ; ok(31, ($FA ? @h == @data : $X->length == @data )); my @new_data = qw(add this to the start of the array) ; diff --git a/t/pragma/warn/op b/t/pragma/warn/op index f3c0548..ab2124e 100644 --- a/t/pragma/warn/op +++ b/t/pragma/warn/op @@ -884,3 +884,15 @@ in begin in mainline in end in end +######## +# op.c +my @x; +use warnings 'misc' ; +push(@x); +unshift(@x); +no warnings 'misc' ; +push(@x); +unshift(@x); +EXPECT +Useless use of push with no arguments at - line 4. +Useless use of unshift with no arguments at - line 5.