From: Yitzchak Scott-Thoennes <sthoenna@efn.org>
Date: Sun, 18 May 2003 19:21:01 +0000 (-0700)
Subject: Re: Possible precedence problem on bitwise ^ operator
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=96a925ab0077cdd24bd7d328f20be3d5373d4885;p=p5sagit%2Fp5-mst-13.2.git

Re: Possible precedence problem on bitwise ^ operator
Message-ID: <N+Dy+gzkg+XX092yn@efn.org>
(with tweaks to perldiag.pod)

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

diff --git a/op.c b/op.c
index 86cfe23..97e6e73 100644
--- a/op.c
+++ b/op.c
@@ -4619,9 +4619,12 @@ Perl_ck_bitop(pTHX_ OP *o)
 	    || o->op_type == OP_BIT_AND
 	    || o->op_type == OP_BIT_XOR)
     {
-	OPCODE typfirst = cBINOPo->op_first->op_type;
-	OPCODE typlast  = cBINOPo->op_first->op_sibling->op_type;
-	if (OP_IS_NUMCOMPARE(typfirst) || OP_IS_NUMCOMPARE(typlast))
+	OP * left = cBINOPo->op_first;
+	OP * right = left->op_sibling;
+	if ((OP_IS_NUMCOMPARE(left->op_type) &&
+		(left->op_flags & OPf_PARENS) == 0) ||
+	    (OP_IS_NUMCOMPARE(right->op_type) &&
+		(right->op_flags & OPf_PARENS) == 0))
 	    if (ckWARN(WARN_PRECEDENCE))
 		Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
 			"Possible precedence problem on bitwise %c operator",
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 2890573..3cd763b 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2996,10 +2996,8 @@ with a numeric comparison operator, like this :
 
 This expression is actually equivalent to C<$x & ($y == 0)>, due to the
 higher precedence of C<==>. This is probably not what you want. (If you
-really meant to write this, disable the warning, or, better, write
-C<$x & ($y == 0 ? 1 : 0)>). (This warning might also be produced when you
-use the bitwise exclusive or, C<^>. Consider using the low-precedence
-C<xor> operator instead. See L<perlop>.)
+really meant to write this, disable the warning, or, better, put the
+parentheses explicitly and write C<$x & ($y == 0)>).
 
 =item Possible unintended interpolation of %s in string