Skip to content

Commit c1bb1d7

Browse files
authored
Fix issue 10012: False positive: mismatching container, not containers (cppcheck-opensource#3222)
* Fix issue 10012: False positive: mismatching container, not containers
1 parent 691f681 commit c1bb1d7

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/checkstl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
690690
return true;
691691
}
692692

693+
if (Token::Match(tok1->astParent(), "%comp%|-")) {
694+
if (astIsIntegral(tok1, false) || astIsIntegral(tok2, false) || astIsFloat(tok1, false) ||
695+
astIsFloat(tok2, false))
696+
return false;
697+
}
693698
const Token* iter1 = getIteratorExpression(tok1);
694699
const Token* iter2 = getIteratorExpression(tok2);
695700
if (iter1 && iter2 && !isSameExpression(true, false, iter1, iter2, mSettings->library, false, false)) {

test/teststl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,16 @@ class TestStl : public TestFixture {
14301430
" }\n"
14311431
"}\n");
14321432
ASSERT_EQUALS("", errout.str());
1433+
1434+
// #10012
1435+
check("struct a {\n"
1436+
" int b;\n"
1437+
" int end() { return b; }\n"
1438+
"};\n"
1439+
"void f(a c, a d) {\n"
1440+
" if (c.end() == d.end()) {}\n"
1441+
"}\n");
1442+
ASSERT_EQUALS("", errout.str());
14331443
}
14341444

14351445
// Dereferencing invalid pointer

0 commit comments

Comments
 (0)