[PATCH] D66043: Add to -Wparentheses case of bitwise-and ("&") and bitwise-or ("|") verses conditional operator ("?:")

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 14:48:52 PDT 2019


jfb added inline comments.


================
Comment at: test/Sema/parentheses.c:156
+
+  (void)(x ^ b ? 1 : 2);  // no warning, ^ is often used as logical xor
+  (void)(x || b ? 1 : 2);  // no warning, logical operator
----------------
rtrieu wrote:
> jfb wrote:
> > I don't understand why `^` is different. What do you mean by "often used as a logical xor`?
> In C++, there's the bitwise operators |, &, and ^.  And there's the logical operators || and &&.  Since there's no ^^ for a logical-xor, many people will just use the bitwise-xor ^ instead.  Since this isn't warning on logical operators, it makes sense to exclude the bitwise-xor that is often used as logical-xor.
So code is often buggy when it uses `|` and `&` as diagnosed by this patch, but is rarely buggy when it uses `^`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66043/new/

https://reviews.llvm.org/D66043





More information about the cfe-commits mailing list