Fix issue 10012: False positive: mismatching container, not containers (#3222)

* Fix issue 10012: False positive: mismatching container, not containers
This commit is contained in:
Paul Fultz II 2021-04-19 02:17:02 -05:00 committed by GitHub
parent 691f681d86
commit c1bb1d771b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -690,6 +690,11 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
return true; return true;
} }
if (Token::Match(tok1->astParent(), "%comp%|-")) {
if (astIsIntegral(tok1, false) || astIsIntegral(tok2, false) || astIsFloat(tok1, false) ||
astIsFloat(tok2, false))
return false;
}
const Token* iter1 = getIteratorExpression(tok1); const Token* iter1 = getIteratorExpression(tok1);
const Token* iter2 = getIteratorExpression(tok2); const Token* iter2 = getIteratorExpression(tok2);
if (iter1 && iter2 && !isSameExpression(true, false, iter1, iter2, mSettings->library, false, false)) { if (iter1 && iter2 && !isSameExpression(true, false, iter1, iter2, mSettings->library, false, false)) {

View File

@ -1430,6 +1430,16 @@ private:
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #10012
check("struct a {\n"
" int b;\n"
" int end() { return b; }\n"
"};\n"
"void f(a c, a d) {\n"
" if (c.end() == d.end()) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// Dereferencing invalid pointer // Dereferencing invalid pointer