[clang-tools-extra] [clang-tidy] Add misc-bool-bitwise-operation check (PR #167552)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 7 06:31:47 PST 2026
================
@@ -0,0 +1,127 @@
+.. title:: clang-tidy - misc-bool-bitwise-operation
+
+misc-bool-bitwise-operation
+===========================
+
+Finds potentially inefficient use of bitwise operators such as ``&``, ``|``
+and their compound analogues on Boolean values where logical operators like
+``&&`` and ``||`` would be more appropriate.
+
+Bitwise operations on Booleans can incur unnecessary performance overhead due
+to implicit integer conversions and missed short-circuit evaluation. They also
+contradict the principle of least astonishment, as logical operators are the
+expected and idiomatic way to work with Boolean values.
+
+.. code-block:: c++
+
+ bool invalid = false;
+ invalid |= x > limit.x; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
----------------
EugeneZelenko wrote:
I don't think that diagnostic should be part of example. Before and after are better way to demonstrate check functionality.
https://github.com/llvm/llvm-project/pull/167552
More information about the cfe-commits
mailing list