Fixed #7449 (reademptycontainer (inconclusive) when variable changed in function )

This commit is contained in:
Daniel Marjamäki 2017-09-15 10:49:58 +02:00
parent 349a28705a
commit d79762cfc3
2 changed files with 27 additions and 0 deletions

View File

@ -1596,6 +1596,17 @@ void CheckStl::readingEmptyStlContainer()
} else if (tok->str() == "{" && tok->next()->scope()->type == Scope::eLambda) } else if (tok->str() == "{" && tok->next()->scope()->type == Scope::eLambda)
tok = tok->link(); tok = tok->link();
// function call
if (Token::Match(tok, "!!. %name% (") && !Token::simpleMatch(tok->linkAt(2), ") {")) {
for (std::map<unsigned int, const Library::Container*>::const_iterator it = emptyContainer.begin(); it != emptyContainer.end();) {
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(it->first);
if (var && (var->isLocal() || var->isArgument()))
++it;
else
it = emptyContainer.erase(it);
}
}
if (!tok->varId()) if (!tok->varId())
continue; continue;

View File

@ -2998,6 +2998,22 @@ private:
"}", true); "}", true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'v'\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'v'\n", errout.str());
// #7449 - nonlocal vector
check("std::vector<int> v;\n"
"void f() {\n"
" v.clear();\n"
" dostuff()\n"
" if (v.empty()) { }\n"
"}", true);
ASSERT_EQUALS("", errout.str());
check("std::vector<int> v;\n"
"void f() {\n"
" v.clear();\n"
" if (v.empty()) { }\n"
"}", true);
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Reading from empty STL container 'v'\n", errout.str());
// #6663 // #6663
check("void foo() {\n" check("void foo() {\n"
" std::set<int> container;\n" " std::set<int> container;\n"