Fixed #2154 (false positive: The loop might unintentionally skip an element in the container)

This commit is contained in:
Daniel Marjamäki 2010-10-30 11:22:30 +02:00
parent 54cb7bf070
commit 7b630cc581
2 changed files with 14 additions and 0 deletions

View File

@ -880,6 +880,9 @@ void CheckStl::missingComparison()
}
const unsigned int &iteratorId(tok2->varId());
if (iteratorId == 0)
continue;
const Token *incrementToken = 0;
unsigned int indentlevel = 0;
// Parse loop..

View File

@ -99,6 +99,7 @@ private:
TEST_CASE(missingInnerComparison2); // no FP when there is comparison
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
// catch common problems when using the string::c_str() function
TEST_CASE(cstr);
@ -1108,6 +1109,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void missingInnerComparison5()
{
check("void f() {\n"
" for(it = map1.begin(); it != map1.end(); it++) {\n"
" str[i++] = (*it).first;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void cstr()
{
check("void f() {\n"