================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to