Fixed #6887 (False positive eraseDereference - container is member of member variable)

This commit is contained in:
Daniel Marjamäki 2015-07-30 10:13:49 +02:00
parent 594d30f7ae
commit 9085fdc156
2 changed files with 11 additions and 1 deletions

View File

@ -395,7 +395,9 @@ void CheckStl::eraseCheckLoopVar(const Scope &scope, const Variable *var)
for (const Token *tok = scope.classStart; tok != scope.classEnd; tok = tok->next()) {
if (tok->str() != "(")
continue;
if (!Token::Match(tok->tokAt(-4), "!!= %name% . erase ( ++| %varid% )", var->declarationId()))
if (!Token::Match(tok->tokAt(-2), ". erase ( ++| %varid% )", var->declarationId()))
continue;
if (Token::simpleMatch(tok->astParent(), "="))
continue;
// Iterator is invalid..
unsigned int indentlevel = 0U;

View File

@ -674,6 +674,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void f()\n"
"{\n"
" std::list<int>::iterator i;\n"
" while (i != x.y.end())\n"
" i = x.y.erase(i);\n"
"}");
ASSERT_EQUALS("", errout.str());
// #2101
check("void f(vector< list<int> > &ints, unsigned int i)\n"
"{\n"