summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2004-02-25 17:10:56 +0000
committerDave Mitchell <davem@fdisolutions.com>2004-02-25 17:10:56 +0000
commite7fec78e344a7fdea63b9a2551a3c57cc1a50f4d (patch)
tree3d20ccd10bcc02d4787a37c60d9c0527deba60c9 /op.c
parentff4091f15699664c73b1648f3e0ba5ff2c76be14 (diff)
downloadperl-e7fec78e344a7fdea63b9a2551a3c57cc1a50f4d.tar.gz
stop "const in void context" warning for a const in an
optimised-away boolean expresssion, eg 5 || print; p4raw-id: //depot/perl@22376
Diffstat (limited to 'op.c')
-rw-r--r--op.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/op.c b/op.c
index 4bd252c567..4273e65dcd 100644
--- a/op.c
+++ b/op.c
@@ -677,10 +677,14 @@ Perl_scalarvoid(pTHX_ OP *o)
else {
if (ckWARN(WARN_VOID)) {
useless = "a constant";
+ /* don't warn on optimised away booleans, eg
+ * use constant F, 5; Foo || print; */
+ if (cSVOPo->op_private & OPpCONST_SHORTCIRCUIT)
+ useless = 0;
/* the constants 0 and 1 are permitted as they are
conventionally used as dummies in constructs like
1 while some_condition_with_side_effects; */
- if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
+ else if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
useless = 0;
else if (SvPOK(sv)) {
/* perl4's way of mixing documentation and code
@@ -3363,11 +3367,13 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
op_free(first);
*firstp = Nullop;
+ other->op_private |= OPpCONST_SHORTCIRCUIT;
return other;
}
else {
op_free(other);
*otherp = Nullop;
+ first->op_private |= OPpCONST_SHORTCIRCUIT;
return first;
}
}