Fixed #8341 (error:iterators not correct)

This commit is contained in:
Daniel Marjamäki 2018-09-02 21:04:45 +02:00
parent 7224ee27d9
commit 756c1d8de7
2 changed files with 10 additions and 6 deletions

View File

@ -363,12 +363,7 @@ void CheckStl::iterators()
// Reassign the iterator // Reassign the iterator
else if (Token::Match(tok2, "%varid% =", iteratorId)) { else if (Token::Match(tok2, "%varid% =", iteratorId)) {
// Assume that the iterator becomes valid. break;
// TODO: add checking that checks if the iterator becomes valid or not
validatingToken = Token::findmatch(tok2->tokAt(2), "[;)]");
// skip ahead
tok2 = tok2->tokAt(2);
} }
// Passing iterator to function. Iterator might be initialized // Passing iterator to function. Iterator might be initialized

View File

@ -56,6 +56,7 @@ private:
TEST_CASE(iterator12); TEST_CASE(iterator12);
TEST_CASE(iterator13); TEST_CASE(iterator13);
TEST_CASE(iterator14); // #8191 TEST_CASE(iterator14); // #8191
TEST_CASE(iterator15); // #8341
TEST_CASE(iteratorExpression); TEST_CASE(iteratorExpression);
TEST_CASE(iteratorSameExpression); TEST_CASE(iteratorSameExpression);
@ -599,6 +600,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void iterator15() {
check("void f(C1* x, std::list<int> a) {\n"
" std::list<int>::iterator pos = a.begin();\n"
" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void iteratorExpression() { void iteratorExpression() {
check("std::vector<int>& f();\n" check("std::vector<int>& f();\n"
"std::vector<int>& g();\n" "std::vector<int>& g();\n"