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

Ryan Beltran via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 24 14:01:00 PDT 2021


rpbeltran added a comment.

In D108003#2956332 <https://reviews.llvm.org/D108003#2956332>, @xbolva00 wrote:

>>> and it would be more of an optimization than correctness issue as far as I understand
>
> Yeah, this is right, indeed.
>
> Maybe @rpbeltran has some idea or motivating cases for OR pattern?

I don't actually have a case off-hand that I've spotted from the real world, but this example snippet seems plausible enough:

  if (queue.empty() || queue.pop() == STOP_TOKEN) {
    break;
  }

Consider that in this scenario, we only consider queue.pop() if the queue is not empty due to short circuiting.

  if (queue.empty() | queue.pop() == STOP_TOKEN) {
    break;
  }

While this scenario calls pop() regardless, likely causing a runtime error if the queue is empty.

I'll run this warning against ChromeOS and see if I spot any interesting results.


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

https://reviews.llvm.org/D108003



More information about the cfe-commits mailing list