This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: Possible precedence problem on bitwise ^ operator
authorYitzchak Scott-Thoennes <sthoenna@efn.org>
Sun, 18 May 2003 19:21:01 +0000 (12:21 -0700)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 19 May 2003 19:20:48 +0000 (19:20 +0000)
Message-ID: <N+Dy+gzkg+XX092yn@efn.org>
(with tweaks to perldiag.pod)

p4raw-id: //depot/perl@19570

op.c
pod/perldiag.pod

diff --git a/op.c b/op.c
index 86cfe23..97e6e73 100644 (file)
--- 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",
index 2890573..3cd763b 100644 (file)
@@ -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