Fixed false positive eraseDereference with range-based for-loops (#7106)

This commit is contained in:
PKEuS 2015-11-08 09:42:28 +01:00
parent 7d6e1974eb
commit 32f0cbb6ad
2 changed files with 13 additions and 1 deletions

View File

@ -89,7 +89,7 @@ void CheckStl::iterators()
}
// the validIterator flag says if the iterator has a valid value or not
bool validIterator = Token::Match(var->nameToken()->next(), "[(=]");
bool validIterator = Token::Match(var->nameToken()->next(), "[(=:]");
const Scope* invalidationScope = 0;
// The container this iterator can be used with

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(stlBoundaries3);
TEST_CASE(stlBoundaries4); // #4364
TEST_CASE(stlBoundaries5); // #4352
TEST_CASE(stlBoundaries6); // #7106
// if (str.find("ab"))
TEST_CASE(if_find);
@ -1478,6 +1479,17 @@ private:
ASSERT_EQUALS("[test.cpp:8]: (error) Invalid iterator 'i' used.\n", errout.str());
}
void stlBoundaries6() { // #7106
check("void foo(std::vector<int>& vec) {\n"
" for (Function::iterator BB : vec) {\n"
" for (int Inst : *BB)\n"
" {\n"
" }\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void if_find() {
// ---------------------------