From 86994c5e3d911d8492960767bf47d9b163e2e5ed Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:13:41 +0100 Subject: [PATCH] Fix #12443 FP mismatchingContainers with container in namespace (#5984) Or should this be fixed elsewhere? If `::` represents the container, `isSameExpression()` should handle that. If `::` is not the container, then it shouldn't be set as `tokvalue`. --- lib/checkstl.cpp | 2 ++ test/teststl.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index d1d10082821..047915a44b0 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -690,6 +690,8 @@ static std::vector getAddressContainer(const Token* tok) { if (Token::simpleMatch(tok, "[") && tok->astOperand1()) return { tok->astOperand1() }; + while (Token::simpleMatch(tok, "::") && tok->astOperand2()) + tok = tok->astOperand2(); std::vector values = ValueFlow::getLifetimeObjValues(tok, /*inconclusive*/ false); std::vector res; for (const auto& v : values) { diff --git a/test/teststl.cpp b/test/teststl.cpp index 252239307a0..f7bf96fb034 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2204,6 +2204,16 @@ class TestStl : public TestFixture { " a.erase(*it);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("namespace N {\n" // #12443 + " std::vector v;\n" + "}\n" + "using namespace N;\n" + "void f() {\n" + " auto it = std::find(v.begin(), v.end(), 0);\n" + " if (it != N::v.end()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void eraseIteratorOutOfBounds() {