[PATCH] D66043: Add to -Wparentheses case of bitwise-and ("&") and bitwise-or ("|") verses conditional operator ("?:")
Richard Trieu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 14:28:03 PDT 2019
rtrieu marked 2 inline comments as done.
rtrieu added inline comments.
================
Comment at: test/Sema/parentheses.c:148
+
+ (void)(x | b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '|'}} expected-note 2{{place parentheses}}
+ (void)(x & b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '&'}} expected-note 2{{place parentheses}}
----------------
MaskRay wrote:
> I hope these `| ? :` `& ? :` warnings are disabled-by-default.
These new warnings reuse the existing parentheses warnings, which is diag::warn_precedence_conditional. That is on by default, so this one as written is also on by default..
================
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
----------------
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.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66043/new/
https://reviews.llvm.org/D66043
More information about the cfe-commits
mailing list