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

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 21:45:14 PDT 2019


MaskRay 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}}
----------------
rtrieu wrote:
> 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..
I agree that 

`cond1 ? 0xf0 : 0x10 | cond2 ? 0x5 : 0x2;` is confusing and justifies a warning. But **what is tested here is different**.

That is why I created D65192, because such warnings are very annoying as enabled-by-default diagnostics.

I think this change will make it even harder to remove some annoying -Wparentheses warnings..


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

https://reviews.llvm.org/D66043





More information about the cfe-commits mailing list