From 2a0a90c1504bdba958e9433cf4a9e32e1e9ce41f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:45:19 +0100 Subject: [PATCH 1/5] Update checkstl.cpp --- lib/checkstl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index aa08725430a..091da9f9b72 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1636,6 +1636,8 @@ static std::pair isMapFind(const Token *tok) return {}; if (!tok->astOperand2()) return {}; + if (!Token::simpleMatch(tok->astParent(), "==")) + return {}; return {contTok, tok->astOperand2()}; } From 07dd101cd9e574f4f7a38738a845aab7d8677b68 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:54:26 +0100 Subject: [PATCH 2/5] Update teststl.cpp --- test/teststl.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/teststl.cpp b/test/teststl.cpp index bb20d2d8182..737f1c8e57e 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -7424,6 +7424,17 @@ class TestStl : public TestFixture { dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); + check("void f(std::map& m) {\n" // #15116 + " if (m.count(1) != 0)\n" + " m[1] = true;\n" + "}\n" + "void g(std::map& m) {\n" + " if (m.count(1) == 1)\n" + " m[1] = true;\n" + "}\n", + dinit(CheckOptions, $.inconclusive = true)); + ASSERT_EQUALS("", errout_str()); // TODO: warn about duplicate search + // #9218 - not small type => do not warn if cpp standard is < c++17 { Settings s = settings; From 758d6dca58fc8d0feb438aad11d66c0f02a987db Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:56:51 +0100 Subject: [PATCH 3/5] Update checkstl.cpp --- lib/checkstl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 091da9f9b72..cb2780aaf5e 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1638,6 +1638,8 @@ static std::pair isMapFind(const Token *tok) return {}; if (!Token::simpleMatch(tok->astParent(), "==")) return {}; + if (tok->astOperand1()->strAt(1) == "count" && (!tok->astParent()->astOperand2()->hasKnownIntValue() || tok->astParent()->getKnownIntValue() != 0) + return {}; return {contTok, tok->astOperand2()}; } From 6d288e64dcd31d64987727cd1be3e75ca95b6ddb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:59:17 +0100 Subject: [PATCH 4/5] 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 cb2780aaf5e..9a317c8c2eb 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1638,7 +1638,7 @@ static std::pair isMapFind(const Token *tok) return {}; if (!Token::simpleMatch(tok->astParent(), "==")) return {}; - if (tok->astOperand1()->strAt(1) == "count" && (!tok->astParent()->astOperand2()->hasKnownIntValue() || tok->astParent()->getKnownIntValue() != 0) + if (tok->astOperand1()->strAt(1) == "count" && (!tok->astParent()->astOperand2()->hasKnownIntValue() || tok->astParent()->astOperand2()->getKnownIntValue() != 0) return {}; return {contTok, tok->astOperand2()}; } From 99b5261b552fbc612b47381e419a62e9967a90f0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 10:03:02 +0100 Subject: [PATCH 5/5] 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 9a317c8c2eb..c72b50dfd5a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1638,7 +1638,7 @@ static std::pair isMapFind(const Token *tok) return {}; if (!Token::simpleMatch(tok->astParent(), "==")) return {}; - if (tok->astOperand1()->strAt(1) == "count" && (!tok->astParent()->astOperand2()->hasKnownIntValue() || tok->astParent()->astOperand2()->getKnownIntValue() != 0) + if (tok->astOperand1()->strAt(1) == "count" && (!tok->astParent()->astOperand2()->hasKnownIntValue() || tok->astParent()->astOperand2()->getKnownIntValue() != 0)) return {}; return {contTok, tok->astOperand2()}; }