CXX.BITOP.BOOL_OPERAND
Potential logic error: Boolean expressions should not be used directly as bitwise operator arguments. Consider using logical operators instead.
This checker reports defects when Boolean operands are used with bitwise operators.
Vulnerable code example
Copy
void func(bool var1, bool var2)
{
int var3 = var1 | var2;
int var4 = var1 & var2;
}
In the above example, lines 3 and 4 are noncompliant because bitwise operators are applied to Boolean variables. Klocwork produces a CXX.BITOP.BOOL_OPERAND defect at lines 3 and 4, indicating “Bitwise operators should be applied to constants only.”
Fixed code example
Copy
void func(bool var1, bool var2)
{
int var3 = 1 | 2;
int var4 = 3 & 4;
}
In the fixed example, Klocwork no longer reports the defect CXX.BITOP.BOOL_OPERAND at lines 3 and 4.