From dbd2e18430313f40a2df6a3079781e95732baa3e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 11 Aug 2026 09:38:58 +0200 Subject: [PATCH 1/3] Update checkstl.cpp --- lib/checkstl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index de1d82792ac..088ccd0d904 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1857,7 +1857,7 @@ void CheckStlImpl::redundantCondition() continue; const Token* tok = scope.classDef->tokAt(2); - if (!Token::Match(tok, "%name% . find ( %any% ) != %name% . end|rend|cend|crend ( ) ) { %name% . remove|erase ( %any% ) ;")) + if (!Token::Match(tok, "%name% . find ( %any% ) != %name% . end|rend|cend|crend ( ) ) { %name% . erase ( %any% ) ;")) continue; // Get tokens for the fields %name% and %any% @@ -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() && From ed73da577591726796b427ff58c4c0310a64a1f3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 11 Aug 2026 09:40:13 +0200 Subject: [PATCH 2/3] Update teststl.cpp --- test/teststl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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() { From 067474dc6c9576087cb743df1db04a8017c3a583 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 11 Aug 2026 09:42:48 +0200 Subject: [PATCH 3/3] Update checkstl.cpp --- lib/checkstl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 088ccd0d904..cf2b671606f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1857,7 +1857,7 @@ void CheckStlImpl::redundantCondition() continue; const Token* tok = scope.classDef->tokAt(2); - if (!Token::Match(tok, "%name% . find ( %any% ) != %name% . end|rend|cend|crend ( ) ) { %name% . erase ( %any% ) ;")) + if (!Token::Match(tok, "%name% . find ( %any% ) != %name% . end|rend|cend|crend ( ) ) { %name% . remove|erase ( %any% ) ;")) continue; // Get tokens for the fields %name% and %any%