Fixed #3433 (False positive: Same iterator is used with both myVector and myMap)

This commit is contained in:
Daniel Marjamäki 2011-12-21 06:16:06 +01:00
parent fd0d9c8694
commit deccb1df06
2 changed files with 25 additions and 0 deletions

View File

@ -112,6 +112,10 @@ void CheckStl::iterators()
continue; // No warning
}
// skip error message if the iterator is erased/inserted by value
if (itTok->previous()->str() == "*")
continue;
// Show error message, mismatching iterator is used.
iteratorsError(tok2, tok->strAt(2), tok2->str());
}

View File

@ -42,6 +42,7 @@ private:
TEST_CASE(iterator8);
TEST_CASE(iterator9);
TEST_CASE(iterator10);
TEST_CASE(iterator11);
TEST_CASE(dereference);
TEST_CASE(dereference_member);
@ -216,6 +217,15 @@ private:
" ints2.insert(it1, it2);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(const std::set<int> &ints1)\n"
"{\n"
" std::set<int> ints2;\n"
" std::set<int>::iterator it1 = ints1.begin();\n"
" std::set<int>::iterator it2 = ints2.end();\n"
" ints2.insert(it1, it2);\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout.str());
}
void iterator7() {
@ -330,6 +340,17 @@ private:
ASSERT_EQUALS("[test.cpp:8]: (error) Same iterator is used with both s1 and s2\n", errout.str());
}
void iterator11() {
// Ticket #3433
check("int main() {\n"
" map<int, int> myMap;\n"
" vector<string> myVector;\n"
" for(vector<int>::iterator x = myVector.begin(); x != myVector.end(); x++)\n"
" myMap.erase(*x);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing invalid pointer
void dereference() {
check("void f()\n"