Fix issue 8736: Iterators to containers from different expressions (a.begin().x == b.begin().x) (#1370)

This commit is contained in:
Paul Fultz II 2018-09-07 00:08:02 -05:00 committed by Daniel Marjamäki
parent a5064b00b6
commit f7e7e9bd3c
2 changed files with 8 additions and 2 deletions

View File

@ -467,9 +467,9 @@ static const Token * getIteratorExpression(const Token * tok)
if (iter2) if (iter2)
return iter2; return iter2;
} else if (Token::Match(tok, "begin|cbegin|rbegin|crbegin|end|cend|rend|crend (")) { } else if (Token::Match(tok, "begin|cbegin|rbegin|crbegin|end|cend|rend|crend (")) {
if (Token::Match(tok->previous(), ". %name% ( )")) if (Token::Match(tok->previous(), ". %name% ( ) !!."))
return tok->previous()->astOperand1(); return tok->previous()->astOperand1();
if (Token::Match(tok, "%name% ( !!)")) if (Token::Match(tok, "%name% ( !!)") && !Token::simpleMatch(tok->linkAt(1), ") ."))
return tok->next()->astOperand2(); return tok->next()->astOperand2();
} }
return nullptr; return nullptr;

View File

@ -705,6 +705,12 @@ private:
" if(f().begin()+1 == f().end()+1) {}\n" " if(f().begin()+1 == f().end()+1) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" if (a.begin().x == b.begin().x) {}\n"
" if (begin(a).x == begin(b).x) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void iteratorSameExpression() { void iteratorSameExpression() {