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).
structTestStruct{intm;};voidSomeInitFunc(TestStruct&Test){Test.m=0;}//cppcheckerroneouslyflagsthisasreturninglocalmemoryint*GetAddressOfStatic(){structStaticStruct{intm;};staticStaticStructTest{0};return&Test.m;}intmain(){//StreamReaderuses<<toreadobjects//ImodifiedisLikelyStreamReadinastutils.cpptocheckfor<<aswellasthematchingcodeincheckclass.cpp.Isthereabetterwayofdoingthis?StreamReaderAr;std::vector<int>test_vec;Ar<<test_vec;printf("%d\n",test_vec[0])//SomeInitFuncusesareferencetoinitialisethestruct(doesnothappenin1.88)TestStruct*Test=newTestStruct();SomeInitFunc(*Test);//passingconstantsascontainersizeparametersdoesnotworkstaticconstintkMax=4;std::array<int,kMax>test_array;test_array[0]=0;//yougetasyntaxerrorifyoucommentoutthemacrodefinition(doesnothappenin1.88)//#define SOME_MACRO_CPPCHECK_DOESNT_KNOW_ABOUT(a,b,c) int a = bSOME_MACRO_CPPCHECK_DOESNT_KNOW_ABOUT(x,0,);}
Last edit: David Brady 2019-07-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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.