Fix issue 10012: False positive: mismatching container, not containers (#3222)
* Fix issue 10012: False positive: mismatching container, not containers
This commit is contained in:
parent
691f681d86
commit
c1bb1d771b
|
@ -690,6 +690,11 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
|
|||
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* iter2 = getIteratorExpression(tok2);
|
||||
if (iter1 && iter2 && !isSameExpression(true, false, iter1, iter2, mSettings->library, false, false)) {
|
||||
|
|
|
@ -1430,6 +1430,16 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue