Fixed #8191 (False positive iterators regression)

This commit is contained in:
Daniel Marjamäki 2018-01-06 22:25:13 +01:00
parent 61767d4932
commit 83b87b54b4
2 changed files with 11 additions and 1 deletions

View File

@ -241,7 +241,7 @@ void CheckStl::iterators()
Token::Match(skipMembers(tok2->tokAt(2)), "begin|rbegin|cbegin|crbegin|find (")) {
validatingToken = skipMembers(tok2->tokAt(2))->linkAt(1);
containerToken = skipMembers(tok2->tokAt(2))->tokAt(-2);
if (containerToken->varId() == 0)
if (containerToken->varId() == 0 || Token::simpleMatch(validatingToken, ") ."))
containerToken = nullptr;
containerAssignScope = tok2->scope();

View File

@ -53,6 +53,7 @@ private:
TEST_CASE(iterator11);
TEST_CASE(iterator12);
TEST_CASE(iterator13);
TEST_CASE(iterator14); // #8191
TEST_CASE(dereference);
TEST_CASE(dereference_break); // #3644 - handle "break"
@ -521,6 +522,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void iterator14() {
check("void f() {\n"
" std::map<int,Foo> x;\n"
" std::map<int,Foo>::const_iterator it;\n"
" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing invalid pointer
void dereference() {
check("void f()\n"