From b247d7d56e5a1f7359697c175333ce8a84eb526b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 13 Jan 2011 20:57:44 +0100 Subject: [PATCH] Fixed #2450 (False positive when iterator reused) --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 91bfd0dfa..96f736b4f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -968,7 +968,7 @@ void CheckStl::missingComparison() incrementToken = tok3; else if (tok3->varId() == iteratorId && Token::Match(tok3->next(), "!=|==")) incrementToken = 0; - else if (tok3->str() == "break") + else if (tok3->str() == "break" || tok3->str() == "return") incrementToken = 0; } if (incrementToken) diff --git a/test/teststl.cpp b/test/teststl.cpp index aeabd69fa..354907310 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1118,6 +1118,16 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("function f1(std::list &l1) {\n" + " for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\n" + " if (*i == 44) {\n" + " l1.insert(++i, 55);\n" + " return;\n" + " }\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void missingInnerComparison5()