From: Rafael Garcia-Suarez Date: Mon, 19 Nov 2001 13:26:45 +0000 (+0100) Subject: new warning "Useless use of sort in scalar context" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a801c63c4c283fdf8af1d9fbd7d3d89096ee73f6;p=p5sagit%2Fp5-mst-13.2.git new warning "Useless use of sort in scalar context" Message-ID: <20011119132645.A15034@rafael> p4raw-id: //depot/perl@13094 --- diff --git a/op.c b/op.c index af125aa..6343a03 100644 --- a/op.c +++ b/op.c @@ -1024,6 +1024,9 @@ Perl_scalar(pTHX_ OP *o) } WITH_THR(PL_curcop = &PL_compiling); break; + case OP_SORT: + if (ckWARN(WARN_VOID)) + Perl_warner(aTHX_ WARN_VOID, "Useless use of sort in scalar context"); } return o; } diff --git a/pod/perldiag.pod b/pod/perldiag.pod index a4c6543..aab7831 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3844,6 +3844,14 @@ about. (W) You did C without any arguments. That isn't very useful. +=item Useless use of sort in scalar context + +(W void) You used sort in scalar context, as in : + + my $x = sort @y; + +This is not very useful, and perl currently optimizes this away. + =item Useless use of %s with no values (W syntax) You used the push() or unshift() function with no arguments diff --git a/t/lib/warnings/op b/t/lib/warnings/op index ab6d773..2fa54b8 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -36,6 +36,9 @@ $a ; "abc" + Useless use of sort in scalar context + my $x = sort (2,1,3); + Applying %s to %s will act on scalar(%s) my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; @a =~ /abc/ ; @@ -332,6 +335,14 @@ Useless use of getpwnam in void context at - line 52. Useless use of getpwuid in void context at - line 53. ######## # op.c +use warnings 'void' ; close STDIN ; +my $x = sort (2,1,3); +no warnings 'void' ; +$x = sort (2,1,3); +EXPECT +Useless use of sort in scalar context at - line 3. +######## +# op.c no warnings 'void' ; close STDIN ; 1 x 3 ; # OP_REPEAT # OP_GVSV