Cppcheck 2.10 reports a false positive when run on a C++ file with the following code. Please see comments in the code for details.
#include<vector>#include<cstdio>template<typenameT>intg(){return0;}intf(intt){std::vector<int>v(1);//theautotypedeductiononthefollowinglineseemstobethecauseof//thefalsepositive,becauseifeither//-thetypeofitrisspecifiedexplicitlyasstd::vector<int>::iterator,or//-g<int>()isreplacedwithanequivalentnon-templatedfunction,//thenthefalsepositiveissueisnolongerreportedbyCppcheck.autoitr=v.begin()+g<int>();std::vector<int>v2(itr,v.end());v.erase(itr,v.end());//Falsepositiveissuewithmessage//"error: Using iterator to local container 'v' that may be invalid. [invalidContainer]"//reportedonthenextlinev.push_back(v2.size());returnv[0];};intmain(intargc,char*argv[]){printf("Answer: %d\n",f(0));return0;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cppcheck 2.10 reports a false positive when run on a C++ file with the following code. Please see comments in the code for details.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11583