From 1fd85c0ae87d5dadd36bd8740409589a4db01a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Feb 2020 19:02:54 +0100 Subject: [PATCH] Fixed #9630 (False positive: in stlIfFind checking, if with initializer is not handled properly) --- lib/checkstl.cpp | 6 +++++- test/teststl.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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