Fixed false positive #4788 (break; in BOOST_FOREACH)

This commit is contained in:
PKEuS 2014-08-31 20:40:52 +02:00
parent 8722bba52a
commit e1bc5f5248
2 changed files with 13 additions and 1 deletions

View File

@ -46,6 +46,8 @@ 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)) {
const Token* nextStatement = Token::findsimplematch(tok2->linkAt(3), ";", end);
if (!Token::Match(nextStatement, "; break|return|throw"))
boostForeachError(tok2);
break;
}

View File

@ -97,6 +97,16 @@ private:
" data.insert(i);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Break after modification (#4788)
check("void f() {\n"
" vector<int> data;\n"
" BOOST_FOREACH(int i, data) {\n"
" data.push_back(123);\n"
" break;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};