Merge pull request #56 from richq/autoptr
Extra check for auto_ptr new[]
This commit is contained in:
commit
20677a6d54
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue