summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c3
-rw-r--r--pod/perldiag.pod8
-rw-r--r--t/lib/warnings/op11
3 files changed, 22 insertions, 0 deletions
diff --git a/op.c b/op.c
index af125aa4af..6343a03578 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 a4c6543bd2..aab783103e 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -3844,6 +3844,14 @@ about.
(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
diff --git a/t/lib/warnings/op b/t/lib/warnings/op
index ab6d773c1f..2fa54b8262 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