Fixed #7449 (reademptycontainer (inconclusive) when variable changed in function )
This commit is contained in:
parent
349a28705a
commit
d79762cfc3
|
@ -1596,6 +1596,17 @@ void CheckStl::readingEmptyStlContainer()
|
|||
} else if (tok->str() == "{" && tok->next()->scope()->type == Scope::eLambda)
|
||||
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())
|
||||
continue;
|
||||
|
||||
|
|
|
@ -2998,6 +2998,22 @@ private:
|
|||
"}", true);
|
||||
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
|
||||
check("void foo() {\n"
|
||||
" std::set<int> container;\n"
|
||||
|
|
Loading…
Reference in New Issue