From: Michael G. Schwern <schwern@pobox.com>
Date: Sun, 23 Dec 2007 11:56:08 +0000 (-0800)
Subject: Re: grep and smart match should warn in void context
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74295f0bd81452f77ee575c561ad4d9e83dca07d;p=p5sagit%2Fp5-mst-13.2.git

Re: grep and smart match should warn in void context
Message-ID: <476EBD58.9050505@pobox.com>

p4raw-id: //depot/perl@32876
---

diff --git a/op.c b/op.c
index 93a8bfd..212ecdd 100644
--- a/op.c
+++ b/op.c
@@ -941,6 +941,7 @@ Perl_scalarvoid(pTHX_ OP *o)
     case OP_GVSV:
     case OP_WANTARRAY:
     case OP_GV:
+    case OP_SMARTMATCH:
     case OP_PADSV:
     case OP_PADAV:
     case OP_PADHV:
@@ -969,6 +970,7 @@ Perl_scalarvoid(pTHX_ OP *o)
     case OP_ANONLIST:
     case OP_ANONHASH:
     case OP_SORT:
+    case OP_GREPWHILE:
     case OP_REVERSE:
     case OP_RANGE:
     case OP_FLIP:
@@ -1008,7 +1010,9 @@ Perl_scalarvoid(pTHX_ OP *o)
     case OP_PROTOTYPE:
       func_ops:
 	if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
-	    useless = OP_DESC(o);
+	    /* Otherwise it's "Useless use of grep iterator" */
+	    useless = (o->op_type == OP_GREPWHILE) ? "grep"
+	                                           : OP_DESC(o);
 	break;
 
     case OP_NOT:
diff --git a/t/lib/warnings/op b/t/lib/warnings/op
index a744590..c201a02 100644
--- a/t/lib/warnings/op
+++ b/t/lib/warnings/op
@@ -211,6 +211,9 @@ eval { getgrgid 1 };	# OP_GGRGID
 eval { getpwnam 1 };	# OP_GPWNAM
 eval { getpwuid 1 };	# OP_GPWUID
 prototype "foo";	# OP_PROTOTYPE
+grep /42/, (1,2);	# OP_GREP
+$a ~~ $b;		# OP_SMARTMATCH
+$a <=> $b;		# OP_NCMP
 EXPECT
 Useless use of repeat (x) in void context at - line 3.
 Useless use of wantarray in void context at - line 5.
@@ -250,6 +253,9 @@ Useless use of getgrgid in void context at - line 51.
 Useless use of getpwnam in void context at - line 52.
 Useless use of getpwuid in void context at - line 53.
 Useless use of subroutine prototype in void context at - line 54.
+Useless use of grep in void context at - line 55.
+Useless use of smart match in void context at - line 56.
+Useless use of numeric comparison (<=>) in void context at - line 57.
 ########
 # op.c
 use warnings 'void' ; close STDIN ;