Fixed #2643 (False positive: iterator increment and insert)
This commit is contained in:
parent
6a2848e50f
commit
6bd56dbe20
|
@ -964,6 +964,13 @@ void CheckStl::missingComparison()
|
|||
incrementToken = 0;
|
||||
else if (tok3->str() == "break" || tok3->str() == "return")
|
||||
incrementToken = 0;
|
||||
else if (Token::Match(tok3, "%varid% = %var% . insert ( ++| %varid% ++| ,", iteratorId))
|
||||
{
|
||||
// skip insertion..
|
||||
tok3 = tok3->tokAt(6)->link();
|
||||
if (!tok3)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (incrementToken)
|
||||
missingComparisonError(incrementToken, tok2->tokAt(16));
|
||||
|
|
|
@ -102,6 +102,7 @@ private:
|
|||
TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing
|
||||
TEST_CASE(missingInnerComparison4); // no FP when "break;" is used
|
||||
TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP
|
||||
TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'
|
||||
|
||||
// catch common problems when using the string::c_str() function
|
||||
TEST_CASE(cstr);
|
||||
|
@ -1250,6 +1251,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void missingInnerComparison6()
|
||||
{
|
||||
check("void f(std::string &s) {\n"
|
||||
" for(string::iterator it = s.begin(); it != s.end(); it++) {\n"
|
||||
" it = s.insert(++it, 0);\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void cstr()
|
||||
{
|
||||
check("void f() {\n"
|
||||
|
|
Loading…
Reference in New Issue