Fixed ticket #503 (Dereferencing after erase() not work if we try to get access to member)
http://sourceforge.net/apps/trac/cppcheck/ticket/503
This commit is contained in:
parent
5db677bc30
commit
347802f819
|
@ -80,6 +80,11 @@ void CheckStl::iterators()
|
|||
dereferenceErasedError(tok2, tok2->strAt(1));
|
||||
tok2 = tok2->tokAt(2);
|
||||
}
|
||||
else if (!validIterator && Token::Match(tok2, "%varid% . %var%", iteratorId))
|
||||
{
|
||||
dereferenceErasedError(tok2, tok2->strAt(0));
|
||||
tok2 = tok2->tokAt(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
TEST_CASE(iterator3);
|
||||
|
||||
TEST_CASE(dereference);
|
||||
TEST_CASE(dereference_member);
|
||||
|
||||
TEST_CASE(STLSize);
|
||||
TEST_CASE(STLSizeNoErr);
|
||||
|
@ -133,6 +134,18 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:6]: (error) Dereferenced iterator 'iter' has been erased\n", errout.str());
|
||||
}
|
||||
|
||||
void dereference_member()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" std::map<int, int> ints;"
|
||||
" std::map<int, int>::iterator iter;\n"
|
||||
" iter = ints.begin();\n"
|
||||
" ints.erase(iter);\n"
|
||||
" std::cout << iter->first << std::endl;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Dereferenced iterator 'iter' has been erased\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void STLSize()
|
||||
|
|
Loading…
Reference in New Issue