[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 15:29:38 PDT 2019
rtrieu marked an inline comment as done.
rtrieu 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
----------------
jfb wrote:
> 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 `^`?
That's correct. From my testing, &&, || and ^ all had low bug finding rates and didn't make sense to include into this warning while | and & had a high bug finding rate.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66043/new/
https://reviews.llvm.org/D66043
More information about the cfe-commits
mailing list