Fixed #8194 (False positive reademptycontainer - range based loop)

This commit is contained in:
Daniel Marjamäki 2017-09-02 22:22:32 +02:00
parent 30f04a5a96
commit 1ecefa045a
2 changed files with 8 additions and 1 deletions

View File

@ -1601,7 +1601,7 @@ void CheckStl::readingEmptyStlContainer()
if (var && !var->isArrayOrPointer() && !var->typeStartToken()->isStandardType()) {
bool insert = false;
if (var->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared
insert = !Token::Match(tok->next(), "[(=]"); // Only if not initialized
insert = !Token::Match(tok->next(), "[(=:]"); // Only if not initialized
} else if (Token::Match(tok, "%var% . clear ( ) ;")) {
insert = true;
}

View File

@ -3059,6 +3059,13 @@ private:
" l();\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(const std::vector<std::string> &v) {\n"
" for (const std::string& s : v) {\n"
" if (s.find(x) != string::npos) {}\n"
" }\n"
"}", true);
ASSERT_EQUALS("", errout.str());
}
};