Question

#ifdef TEST
#define INVALID_HANDLE_VALUE 0
#else
#include <windows.h>
#endif


int main()
{
HANDLE hf = 0;
if (hf==0 || hf==INVALID_HANDLE_VALUE)
{}
}

above is my test code, when I use cppcheck.exe(1.58) to check this code, cppcheck will give me a 'style' error like enter image description here this seems to be cppcheck think hf == 0 and hf == INVALID_HANDLE_VALUE are same expression. can anyone tell me is this cppcheck's bug or why this code is style error

Was it helpful?

Solution

I am a Cppcheck developer.

I agree that is a wrong warning.

However Cppcheck preprocess the code. So if you do want to have warnings about real issues then it's inevitable with such false warnings (the conditions are logically the same).

Maybe this check should be activated by --inconclusive, since there can be false warnings when macros are used.

If you can live with the false warning then I'd suggest that you do it. If you want that this is fixed then feel free to write a ticket: http://sourceforge.net/apps/trac/cppcheck/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top