Skip to content

Commit

Permalink
Fix #12443 FP mismatchingContainers with container in namespace (#5984)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
chrchr-github committed Feb 27, 2024
1 parent 589ceed commit 86994c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ static std::vector<const Token*> getAddressContainer(const Token* tok)
{
if (Token::simpleMatch(tok, "[") && tok->astOperand1())
return { tok->astOperand1() };
while (Token::simpleMatch(tok, "::") && tok->astOperand2())
tok = tok->astOperand2();
std::vector<ValueFlow::Value> values = ValueFlow::getLifetimeObjValues(tok, /*inconclusive*/ false);
std::vector<const Token*> res;
for (const auto& v : values) {
Expand Down
10 changes: 10 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,16 @@ class TestStl : public TestFixture {
" a.erase(*it);\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("namespace N {\n" // #12443
" std::vector<int> 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() {
Expand Down

0 comments on commit 86994c5

Please sign in to comment.