diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index de1d82792ac..cf2b671606f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1867,6 +1867,9 @@ void CheckStlImpl::redundantCondition() const Token *var3 = var2->tokAt(7); const Token *any2 = var3->tokAt(4); + if (any2->tokAt(3) != scope.bodyEnd) + continue; + // Check if all the "%name%" fields are the same and if all the "%any%" are the same.. if (var1->str() == var2->str() && var2->str() == var3->str() && diff --git a/test/teststl.cpp b/test/teststl.cpp index 2570059c19e..1cc11029804 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4556,6 +4556,16 @@ class TestStl : public TestFixture { " haystack.remove(needle);" "}"); ASSERT_EQUALS("[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\n", errout_str()); + + check("void g(const std::string&);\n" // #14725 + "std::set g_s;\n" + "void f(const std::string& k) {\n" + " if (g_s.find(k) != g_s.end()) {\n" + " g_s.erase(k);\n" + " g(k);\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout_str()); } void missingInnerComparison1() {