with --enable=style: test.cpp:6:11: style: inconclusive: Boolean expression 'b1' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]
return b1 & b2;
^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've seen this mistake made at multiple companies and it seems like an easy check to add if it doesn't already exist (passed without issue for me).
bool bitwiseIncorrectUsageExample()
{
bool b1 = std::rand() % 2 == 1;
bool b2 = std::rand() % 3 == 1;
return b1 & b2;
}
with
--enable=style
:test.cpp:6:11: style: inconclusive: Boolean expression 'b1' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean] return b1 & b2; ^
Well, I swear I've seen the warning before. I am using 2.14 in Ubuntu 22.04 and have pulled and built it myself and I'm already using --enable=all.
I went ahead and made a new file called test.cpp and put that code in it and did
cppcheck --enable=style test.cpp
and I don't get a warning.
--inconclusive
needs to be passed as well. I always use that flag, so it's easy to forget about it.Yes, now I see it, thanks. Maybe this one shouldn't be inconclusive?
Last edit: Steve Albright 2024-08-02