fix #2887 (infinit loop with ( A::A(std::auto_ptr<X> e){} ))

This commit is contained in:
Robert Reif 2011-08-04 19:50:18 -04:00
parent 57a51128a4
commit 2516aad31d
2 changed files with 19 additions and 15 deletions

View File

@ -1138,26 +1138,27 @@ void CheckStl::checkAutoPointer()
{
tok3 = tok3->next();
}
if (!tok3)
continue;
tok3 = tok3->previous()->previous();
if (Token::simpleMatch(tok3->previous(), "[ ] )"))
if (tok3)
{
autoPointerArrayError(tok2->next());
}
else if (tok3->varId())
{
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid% = new %type% [", tok3->varId());
if (decltok)
tok3 = tok3->previous()->previous();
if (Token::simpleMatch(tok3->previous(), "[ ] )"))
{
autoPointerArrayError(tok2->next());
}
else if (tok3->varId())
{
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid% = new %type% [", tok3->varId());
if (decltok)
{
autoPointerArrayError(tok2->next());
}
}
if (tok2->next()->varId())
{
autoPtrVarId.insert(tok2->next()->varId());
}
break;
}
if (tok2->next()->varId())
{
autoPtrVarId.insert(tok2->next()->varId());
}
break;
}
tok2 = tok2->next();
}

View File

@ -1424,6 +1424,9 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
// ticket #1887 infinite loop
check("A::A(std::auto_ptr<X> e){}\n");
ASSERT_EQUALS("", errout.str());
}