Skip to content

Commit 225c128

Browse files
t-a-kmauke
authored andcommitted
op.c: Enable "Useless use of %s in void context" warning for chained comparisons
This particular warning is not issued for chained comparisons such as `1 < $a < 2` in void context before this change. t/lib/warnings/op: Add tests for this warning.
1 parent 1a21aba commit 225c128

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

op.c

+1
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,7 @@ Perl_scalarvoid(pTHX_ OP *arg)
22342234
case OP_GETLOGIN:
22352235
case OP_PROTOTYPE:
22362236
case OP_RUNCV:
2237+
case OP_CMPCHAIN_AND:
22372238
func_ops:
22382239
if ( (PL_opargs[o->op_type] & OA_TARGLEX)
22392240
&& (o->op_private & OPpTARGET_MY)

pod/perldelta.pod

+6
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ negation (C<!!>) is used as a convert-to-boolean operator.
238238

239239
=item *
240240

241+
L<Useless use of %s in void context|perldiag/"Useless use of %s in void context">
242+
243+
This warning now triggers for use of a chained comparison like C<< 0 < $x < 1 >>.
244+
245+
=item *
246+
241247
XXX Describe change here
242248

243249
=back

t/lib/warnings/op

+6-2
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ $a <=> $b; # OP_NCMP
422422
"dsatrewq";
423423
"diatrewq";
424424
"igatrewq";
425+
0 <= $a; # OP_LE
425426
use 5.015;
426427
__SUB__ ; # OP_RUNCV
427428
[]; # OP_ANONLIST
428429
grep /42/, (1,2); # OP_GREP. Not warned about (yet). Grep git logs for void_unusual to see why...
430+
0 <= $a < 10; # OP_CMPCHAIN_AND
429431
EXPECT
430432
Useless use of a constant ("111") in void context at - line 2.
431433
Useless use of repeat (x) in void context at - line 3.
@@ -470,8 +472,10 @@ Useless use of numeric comparison (<=>) in void context at - line 55.
470472
Useless use of a constant ("dsatrewq") in void context at - line 56.
471473
Useless use of a constant ("diatrewq") in void context at - line 57.
472474
Useless use of a constant ("igatrewq") in void context at - line 58.
473-
Useless use of __SUB__ in void context at - line 60.
474-
Useless use of anonymous array ([]) in void context at - line 61.
475+
Useless use of numeric le (<=) in void context at - line 59.
476+
Useless use of __SUB__ in void context at - line 61.
477+
Useless use of anonymous array ([]) in void context at - line 62.
478+
Useless use of comparison chaining in void context at - line 64.
475479
########
476480
# op.c
477481
use warnings 'scalar' ; close STDIN ;

0 commit comments

Comments
 (0)