From 756c1d8de727e02621e5ea2a26b9adce1c557a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Sep 2018 21:04:45 +0200 Subject: [PATCH] Fixed #8341 (error:iterators not correct) --- lib/checkstl.cpp | 7 +------ test/teststl.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 58a0fbbec..8c8408ce3 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -363,12 +363,7 @@ void CheckStl::iterators() // Reassign the iterator else if (Token::Match(tok2, "%varid% =", iteratorId)) { - // Assume that the iterator becomes valid. - // TODO: add checking that checks if the iterator becomes valid or not - validatingToken = Token::findmatch(tok2->tokAt(2), "[;)]"); - - // skip ahead - tok2 = tok2->tokAt(2); + break; } // Passing iterator to function. Iterator might be initialized diff --git a/test/teststl.cpp b/test/teststl.cpp index 6cac1cd7e..8971a1cb9 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -56,6 +56,7 @@ private: TEST_CASE(iterator12); TEST_CASE(iterator13); TEST_CASE(iterator14); // #8191 + TEST_CASE(iterator15); // #8341 TEST_CASE(iteratorExpression); TEST_CASE(iteratorSameExpression); @@ -599,6 +600,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void iterator15() { + check("void f(C1* x, std::list a) {\n" + " std::list::iterator pos = a.begin();\n" + " for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void iteratorExpression() { check("std::vector& f();\n" "std::vector& g();\n"