From 20e56c542d7acafac97216218701e50183a63556 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 14 Feb 2024 12:02:37 +0100 Subject: [PATCH] Fix #12443 FP mismatchingContainers with container in namespace --- 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() {