From e1bc5f52482a7c4fbf7d5a65ece0999d06c0e9e9 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 31 Aug 2014 20:40:52 +0200 Subject: [PATCH] Fixed false positive #4788 (break; in BOOST_FOREACH) --- lib/checkboost.cpp | 4 +++- test/testboost.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkboost.cpp b/lib/checkboost.cpp index fc1130ba9..779cd87e4 100644 --- a/lib/checkboost.cpp +++ b/lib/checkboost.cpp @@ -46,7 +46,9 @@ void CheckBoost::checkBoostForeachModification() const Token *end = tok2->link(); for (; tok2 != end; tok2 = tok2->next()) { if (Token::Match(tok2, "%varid% . insert|erase|push_back|push_front|pop_front|pop_back|clear|swap|resize|assign|merge|remove|remove_if|reverse|sort|splice|unique|pop|push", container_id)) { - boostForeachError(tok2); + const Token* nextStatement = Token::findsimplematch(tok2->linkAt(3), ";", end); + if (!Token::Match(nextStatement, "; break|return|throw")) + boostForeachError(tok2); break; } } diff --git a/test/testboost.cpp b/test/testboost.cpp index 5dba23203..f869d12a7 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -97,6 +97,16 @@ private: " data.insert(i);\n" "}"); ASSERT_EQUALS("", errout.str()); + + // Break after modification (#4788) + check("void f() {\n" + " vector data;\n" + " BOOST_FOREACH(int i, data) {\n" + " data.push_back(123);\n" + " break;\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };