Fixed #5467 (False positive incorrectly claiming use after erase)

This commit is contained in:
Daniel Marjamäki 2014-04-09 10:32:56 +02:00
parent a9e53026bd
commit 59cd1879db
2 changed files with 10 additions and 0 deletions

View File

@ -77,6 +77,9 @@ void CheckStl::iterators()
if (!var || !var->isLocal() || !Token::Match(var->typeEndToken(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator|auto"))
continue;
if (var->typeEndToken()->str() == "auto" && !Token::Match(var->typeEndToken(), "auto %var% ; %var% = %var% . begin|end ( )"))
continue;
if (var->type()) { // If it is defined, ensure that it is defined like an iterator
// look for operator* and operator++
const Function* end = var->type()->getFunction("operator*");

View File

@ -506,6 +506,13 @@ private:
" std::cout << (*iter) << std::endl;\n"
"}");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (error) Iterator 'iter' used after element has been erased.\n", errout.str());
check("void f() {\n"
" auto x = *myList.begin();\n"
" myList.erase(x);\n"
" auto b = x.first;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void STLSize() {