diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 55880485c..37e9d5c20 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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(); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 8edd73225..aa28e834a 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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 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 p2;\n"