Fix ticket #248 (STL erase check broken?)
http://apps.sourceforge.net/trac/cppcheck/ticket/248
This commit is contained in:
parent
c71e29829d
commit
1f53fb7149
|
@ -194,7 +194,7 @@ void CheckStl::eraseCheckLoop(const Token *it)
|
|||
else if (tok->str() == "}")
|
||||
{
|
||||
--indentlevel;
|
||||
if (indentlevel < 0)
|
||||
if (indentlevel <= 0)
|
||||
break;
|
||||
}
|
||||
else if (Token::Match(tok, "break|return|goto") || Token::simpleMatch(tok, (it->str() + " =").c_str()))
|
||||
|
|
|
@ -152,14 +152,28 @@ private:
|
|||
|
||||
void erase()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||
" {\n"
|
||||
" foo.erase(it);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||
" {\n"
|
||||
" foo.erase(it);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
check("for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||
"{\n"
|
||||
" foo.erase(it);\n"
|
||||
"}\n"
|
||||
"for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||
"{\n"
|
||||
" foo.erase(it);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of erase\n[test.cpp:7]: (error) Dangerous usage of erase\n", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void eraseBreak()
|
||||
|
|
Loading…
Reference in New Issue