Fixed #9630 (False positive: in stlIfFind checking, if with initializer is not handled properly)

This commit is contained in:
Daniel Marjamäki 2020-02-18 19:02:54 +01:00
parent afb5590741
commit 1fd85c0ae8
2 changed files with 9 additions and 1 deletions

View File

@ -1092,7 +1092,11 @@ void CheckStl::if_find()
if ((scope.type != Scope::eIf && scope.type != Scope::eWhile) || !scope.classDef)
continue;
for (const Token *tok = scope.classDef->next(); tok->str() != "{"; tok = tok->next()) {
const Token *conditionStart = scope.classDef->next();
if (conditionStart && Token::simpleMatch(conditionStart->astOperand2(), ";"))
conditionStart = conditionStart->astOperand2();
for (const Token *tok = conditionStart; tok->str() != "{"; tok = tok->next()) {
const Token* funcTok = nullptr;
const Library::Container* container = nullptr;

View File

@ -2496,6 +2496,10 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void f(std::set<int> s) {\n"
" if (auto result = s.find(123); result != s.end()) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
// ---------------------------
// std::find