From dbb176dc5aacdd844a1ec150c475933523980a77 Mon Sep 17 00:00:00 2001 From: TAKAI Kousuke <62541129+t-a-k@users.noreply.github.com> Date: Sat, 1 Feb 2025 00:50:50 +0900 Subject: [PATCH] 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. --- op.c | 1 + pod/perldelta.pod | 6 ++++++ t/lib/warnings/op | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 27a91c55b8a8..0a25e59c1eee 100644 --- a/op.c +++ b/op.c @@ -2234,6 +2234,7 @@ Perl_scalarvoid(pTHX_ OP *arg) case OP_GETLOGIN: case OP_PROTOTYPE: case OP_RUNCV: + case OP_CMPCHAIN_AND: func_ops: if ( (PL_opargs[o->op_type] & OA_TARGLEX) && (o->op_private & OPpTARGET_MY) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 2415c8204fe2..3b0666846495 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -238,6 +238,12 @@ negation (C) is used as a convert-to-boolean operator. =item * +L + +This warning now triggers for use of a chained comparison like C<< 0 < $x < 1 >>. + +=item * + XXX Describe change here =back diff --git a/t/lib/warnings/op b/t/lib/warnings/op index efb1d3965992..336890bd5c0d 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -422,10 +422,12 @@ $a <=> $b; # OP_NCMP "dsatrewq"; "diatrewq"; "igatrewq"; +0 <= $a; # OP_LE use 5.015; __SUB__ ; # OP_RUNCV []; # OP_ANONLIST grep /42/, (1,2); # OP_GREP. Not warned about (yet). Grep git logs for void_unusual to see why... +0 <= $a < 10; # OP_CMPCHAIN_AND EXPECT Useless use of a constant ("111") in void context at - line 2. 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. Useless use of a constant ("dsatrewq") in void context at - line 56. Useless use of a constant ("diatrewq") in void context at - line 57. Useless use of a constant ("igatrewq") in void context at - line 58. -Useless use of __SUB__ in void context at - line 60. -Useless use of anonymous array ([]) in void context at - line 61. +Useless use of numeric le (<=) in void context at - line 59. +Useless use of __SUB__ in void context at - line 61. +Useless use of anonymous array ([]) in void context at - line 62. +Useless use of comparison chaining in void context at - line 64. ######## # op.c use warnings 'scalar' ; close STDIN ;