1. case WM_ENABLE: // 0x00a
2. // Is the state changing?
3. if((wParam == 0 ? false : true) != m_bEnabled)
4. {
5. // Change the state
6. m_bEnabled = !m_bEnabled;
7. }
8. break;
CppCheck v1.88 gives error compareBoolExpressionWithInt on line 3.
Why is that? The wParam gets compared to an int (0), after which everything between the round brackets becomes either 'false' or 'true'. Then that gets compared to m_bEnabled, which is a bool.
Why does this warning occur?
Last edit: Sander Bouwhuis 2019-08-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just encountered this issue, but on a different type of code.
#include<variant>template<typenameVariant>autovcheck1() {
returnstd::variant_size_v<Variant>-1; // <- this one has the issue
}
template<typenameVariant>autovcheck2() {
returnstd::variant_size<Variant>::value-1; // <- this one has not
}
Problem exists in trunk.
Last edit: Fabio 2020-09-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the following code (m_bEnabled is a bool):
CppCheck v1.88 gives error compareBoolExpressionWithInt on line 3.
Why is that? The wParam gets compared to an int (0), after which everything between the round brackets becomes either 'false' or 'true'. Then that gets compared to m_bEnabled, which is a bool.
Why does this warning occur?
Last edit: Sander Bouwhuis 2019-08-29
With the following simplified C++ code i can reproduce it with 1.89 dev:
Output:
Looks like a false positive to me.
If i am not missing anything this warning should not be shown.
Last edit: versat 2019-08-29
I have created a ticket for this: https://trac.cppcheck.net/ticket/9304
Thanks. It's always good news when false positives can be fixed.
I rewrote it to this:
Now CppCheck doesn't fail anymore.
This issue should be fixed with https://github.com/danmar/cppcheck/pull/2131
Last edit: Ken-Patrick Lehrmann 2019-08-31
Just encountered this issue, but on a different type of code.
Problem exists in trunk.
Last edit: Fabio 2020-09-06