Extra check for auto_ptr new[]

This fixes cases like this:

   auto_ptr<foo> bar(new foo[10]);

which previously did not work correctly.
This commit is contained in:
Richard Quirk 2011-11-05 15:40:50 +01:00
parent 2a46c635f6
commit 68202d8ffb
2 changed files with 10 additions and 0 deletions

View File

@ -1101,6 +1101,10 @@ void CheckStl::checkAutoPointer()
while (tok2) {
if (Token::Match(tok2, "> %var%")) {
const Token *tok3 = tok2->next()->next();
if (Token::Match(tok3, "( new %type% [")) {
autoPointerArrayError(tok2->next());
break;
}
while (tok3 && tok3->str() != ";") {
tok3 = tok3->next();
}

View File

@ -1433,6 +1433,12 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (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());
check("void f() \n"
"{\n"
" auto_ptr<T> p2( new T[5] );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (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());
check("void f() \n"
"{\n"
" auto_ptr<T> p2;\n"