Fixed ticket #573 (False positive of set range check when we dereferencing iterator)

http://sourceforge.net/apps/trac/cppcheck/ticket/573
This commit is contained in:
Slava Semushin 2009-08-09 02:07:33 +07:00
parent eebb1671a5
commit 5f3baba178
2 changed files with 19 additions and 1 deletions

View File

@ -409,7 +409,7 @@ void CheckStl::stlBoundries()
break;
--indentlevel;
}
else if (Token::Match(tok2, "%varid% <", iteratorid))
else if (Token::Match(tok2, "!!* %varid% <", iteratorid))
{
stlBoundriesError(tok2, container_name);
}

View File

@ -61,6 +61,7 @@ private:
TEST_CASE(stlBoundries1);
TEST_CASE(stlBoundries2);
TEST_CASE(stlBoundries3);
}
void check(const char code[])
@ -425,6 +426,23 @@ private:
ASSERT_EQUALS("", errout.str());
}
void stlBoundries3()
{
const std::string checkStr("void f()\n"
"{\n"
" set<int> files;\n"
" set<int>::const_iterator current;\n"
" for (current = files.begin(); current != files.end(); ++current)\n"
" {\n"
" assert(*current < 100)\n"
" }\n"
"}\n");
check(checkStr.c_str());
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestStl)