Change 13094 by jhi@alpha on 2001/11/19 14:09:34
Subject: [PATCH] new warning "Useless use of sort in scalar context"
From: Rafael Garcia-Suarez <[EMAIL PROTECTED]>
Date: Mon, 19 Nov 2001 13:26:45 +0100
Message-ID: <20011119132645.A15034@rafael>
Affected files ...
.... //depot/perl/op.c#453 edit
.... //depot/perl/pod/perldiag.pod#246 edit
.... //depot/perl/t/lib/warnings/op#7 edit
Differences ...
==== //depot/perl/op.c#453 (text) ====
Index: perl/op.c
--- perl/op.c.~1~ Mon Nov 19 07:15:05 2001
+++ perl/op.c Mon Nov 19 07:15:05 2001
@@ -1024,6 +1024,9 @@
}
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;
}
==== //depot/perl/pod/perldiag.pod#246 (text) ====
Index: perl/pod/perldiag.pod
--- perl/pod/perldiag.pod.~1~ Mon Nov 19 07:15:05 2001
+++ perl/pod/perldiag.pod Mon Nov 19 07:15:05 2001
@@ -3844,6 +3844,14 @@
(W) You did C<use re;> 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
==== //depot/perl/t/lib/warnings/op#7 (text) ====
Index: perl/t/lib/warnings/op
--- perl/t/lib/warnings/op.~1~ Mon Nov 19 07:15:05 2001
+++ perl/t/lib/warnings/op Mon Nov 19 07:15:05 2001
@@ -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 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
End of Patch.