[PATCH] D108003: [Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 26 09:02:31 PDT 2021


Quuxplusone added a comment.

LGTM % comments, FWIW.



================
Comment at: clang/test/Sema/warn-bitwise-and-bool.c:26
+  b = foo() & a;
+  b = (p != 0) & (*p == 42);
+  b = foo() & (*q == 42); // expected-warning {{use of bitwise '&' with boolean operands}}
----------------
Perhaps add a `TODO FIXME` comment here? I still think this should be fixed, but I'm willing to believe that it's unduly difficult and defer it to later. :)


================
Comment at: clang/test/Sema/warn-bitwise-and-bool.c:27
+  b = (p != 0) & (*p == 42);
+  b = foo() & (*q == 42); // expected-warning {{use of bitwise '&' with boolean operands}}
+  b = a & foo();
----------------
For each warning case (or at least for one or two of them), could we also test (my suggested) suppression mechanism?  I think it "obviously" just works, but it'd be good to test explicitly that it works.
```
b = foo() & (int)(*q == 42);  // OK, no warning expected
```


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

https://reviews.llvm.org/D108003



More information about the cfe-commits mailing list