diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index db30455a1..e43b21614 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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; diff --git a/test/teststl.cpp b/test/teststl.cpp index 3ca8cfab1..b4b093c08 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2496,6 +2496,10 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f(std::set s) {\n" + " if (auto result = s.find(123); result != s.end()) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); // --------------------------- // std::find