Since cppcheck 1.90 bitwiseOnBoolean occurs with bool shift+bitwise OR:
#include <inttypes.h> #include <stdio.h> int main() { bool f1 = true, f2 = false, f3 = true; uint32_t num = (f3 << 3) | (f2 << 2) | (f1 << 1); printf("%#x\n", num); return 0; }
test.cpp:7:30: style:inconclusive: Boolean expression 'f3<<3' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean] uint32_t num = (f3 << 3) | (f2 << 2) | (f1 << 1); ^ test.cpp:7:42: style:inconclusive: Boolean expression 'f1<<1' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean] uint32_t num = (f3 << 3) | (f2 << 2) | (f1 << 1); ^
Looks like false positive.
Yes that looks wrong. The boolean variables are cast to integers and the shifted. So clearly there is no boolean any longer. Cppcheck should know that, no reason to mark it inconclusive I guess.
Maybe this message is intended, I am not sure. I created a ticket for this: https://trac.cppcheck.net/ticket/9586
Log in to post a comment.
Since cppcheck 1.90 bitwiseOnBoolean occurs with bool shift+bitwise OR:
Looks like false positive.
Yes that looks wrong.
The boolean variables are cast to integers and the shifted. So clearly there is no boolean any longer. Cppcheck should know that, no reason to mark it inconclusive I guess.
Maybe this message is intended, I am not sure.
I created a ticket for this: https://trac.cppcheck.net/ticket/9586
Last edit: versat 2020-01-20