Everytime I get errors stating 'multiCondition':
line 9 : 'Expression is always false because 'else if' condition matches previous condition at line 7.
line 11 : 'Expression is always false because 'else if' condition matches previous condition at line 7.
In this case there are only 2 'else if' constructions, but if there are more I get errors for all of them.
Obviously, m_hComboDsn and m_hComboSite and m_hComboMember are different HWND handles.
Why is this error thrown?
Last edit: Sander Bouwhuis 2019-08-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When usíng --platform=win64 i can reproduce these messages.
In the Cppcheck windows library configuration HWND is configured as a void pointer.
According to the debug output Cppcheck sees something like this:
I remember that i have created a ticket regarding these functional cast expressions some time ago: https://trac.cppcheck.net/ticket/8969
Maybe they still do not always work as they should.
If i surround the HWNDwith brackets (like this: if((HWND)(lParam) == m_hComboDsn) there are no strange warnings any longer.
I will try to create a useful ticket for this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As far as i see it is not a constructor, it is just another kind of cast. HWND is no class or struct as far as i know, so there is no constructor.
Looking into the Cppcheck code with Visual Studio it shows me that HWND is defined via
So HWND is a pointer to a struct. Thus it has no constructor.
The Cppcheck configuration that tells Cppcheck that HWND is a void * is not completely wrong i would say. It should be useful for the analysis.
The issue is with the functional cast expression vs. a C-style cast expression.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have many constructions like this in my code:
Everytime I get errors stating 'multiCondition':
line 9 : 'Expression is always false because 'else if' condition matches previous condition at line 7.
line 11 : 'Expression is always false because 'else if' condition matches previous condition at line 7.
In this case there are only 2 'else if' constructions, but if there are more I get errors for all of them.
Obviously, m_hComboDsn and m_hComboSite and m_hComboMember are different HWND handles.
Why is this error thrown?
Last edit: Sander Bouwhuis 2019-08-30
When usíng
--platform=win64
i can reproduce these messages.In the Cppcheck windows library configuration
HWND
is configured as avoid
pointer.According to the debug output Cppcheck sees something like this:
I remember that i have created a ticket regarding these functional cast expressions some time ago: https://trac.cppcheck.net/ticket/8969
Maybe they still do not always work as they should.
If i surround the
HWND
with brackets (like this:if((HWND)(lParam) == m_hComboDsn)
there are no strange warnings any longer.I will try to create a useful ticket for this.
I have created a ticket for this: https://trac.cppcheck.net/ticket/9307
Thanks for reporting
So it has to do with the difference between a cast and a constructor?
cast : (HWND)lParam
constructor : HWND(lParam)
I always use the second notation, because almost all classes have a bunch of constructors, but not many classes have explicit cast functions.
As far as i see it is not a constructor, it is just another kind of cast.
HWND
is no class or struct as far as i know, so there is no constructor.Looking into the Cppcheck code with Visual Studio it shows me that
HWND
is defined viaDECLARE_HANDLE is defined in the following way:
This expands to:
So
HWND
is a pointer to astruct
. Thus it has no constructor.The Cppcheck configuration that tells Cppcheck that
HWND
is avoid *
is not completely wrong i would say. It should be useful for the analysis.The issue is with the functional cast expression vs. a C-style cast expression.