Just FYI, I've just checked a recent version of cppcheck on our substantial UnrealEngine-based codebase, and found a few false positives you might not be aware of, as detailed below (note that this code won't compile though, it's just for testing cppcheck).
Thanks! Such feedback from real world code is always great :)
I am not sure about the syntax error for the macro. If Cppcheck does not know this macro there really is a syntax error. So it could be correct to report it.
You can tell Cppcheck about such a macro with a config file, for example:
<?xml version="1.0"?><defformat="2"><definename="SOME_MACRO_CPPCHECK_DOESNT_KNOW_ABOUT(a,b,c)"value="int a = b"/></def>
Then Cppcheck does not throw a syntax error and i see some of the issues you describe:
$ ./cppcheck --enable=style --library=false_positives --template=gcc false_positives.cpp
Checking false_positives.cpp ...
false_positives.cpp:16:12: warning: Returning pointer to local variable 'm' that will be invalid when returning. [returnDanglingLifetime]return&Test.m;
^
false_positives.cpp:16:12: note: Address of variable taken here.
return&Test.m;
^
false_positives.cpp:14:30: note: Variable created here.
struct StaticStruct {int m;};
^
false_positives.cpp:16:12: note: Returning pointer to local variable 'm' that will be invalid when returning.
return&Test.m;
^
false_positives.cpp:26:28: warning: Out of bounds access in expression 'test_vec[0]' because 'test_vec' is empty. [containerOutOfBounds]
printf("%d\n", test_vec[0])
^
false_positives.cpp:35:15: warning: Out of bounds access in expression 'test_array[0]' because 'test_array' is empty. [containerOutOfBounds]
test_array[0]=0;
^
false_positives.cpp:35:19: warning: Variable 'test_array[0]' is assigned a value that is never used. [unreadVariable]
test_array[0]=0;
^
false_positives.cpp:39:0: warning: Variable 'x' is assigned a value that is never used. [unreadVariable]
SOME_MACRO_CPPCHECK_DOESNT_KNOW_ABOUT(x, 0,);
^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just FYI, I've just checked a recent version of cppcheck on our substantial UnrealEngine-based codebase, and found a few false positives you might not be aware of, as detailed below (note that this code won't compile though, it's just for testing cppcheck).
Last edit: David Brady 2019-07-11
Thanks! Such feedback from real world code is always great :)
I am not sure about the syntax error for the macro. If Cppcheck does not know this macro there really is a syntax error. So it could be correct to report it.
You can tell Cppcheck about such a macro with a config file, for example:
Then Cppcheck does not throw a syntax error and i see some of the issues you describe:
I created a ticket for the false positive of returning pointer to local memory: https://trac.cppcheck.net/ticket/9201
I am not sure about the other issues. Can someone else have a look please?
That is more or less the proper approach. The special handling of StreamReader should be configured with --library configuration.
I created https://trac.cppcheck.net/ticket/9202 for the std::array false positive.
I don't see the problem. I see no warning and as far as I can see there should not be a warning.