add new (nothrow) support to CheckUnusedVar::checkFunctionVariableUsage
This commit is contained in:
parent
acebc635b5
commit
477d1e92c9
|
@ -1204,8 +1204,15 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
|
||||
if (start->strAt(2) == "new")
|
||||
{
|
||||
const Token *type = start->tokAt(3);
|
||||
|
||||
// skip nothrow
|
||||
if (Token::Match(type, "( nothrow )") ||
|
||||
Token::Match(type, "( std :: nothrow )"))
|
||||
type = type->link()->next();
|
||||
|
||||
// is it a user defined type?
|
||||
if (!start->tokAt(3)->isStandardType())
|
||||
if (!type->isStandardType())
|
||||
{
|
||||
if (!isRecordTypeWithoutSideEffects(start))
|
||||
allocate = false;
|
||||
|
|
|
@ -2711,6 +2711,20 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" char* ptr = new ( nothrow ) char[16];\n"
|
||||
" delete[] ptr;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" char* ptr = new ( std::nothrow ) char[16];\n"
|
||||
" delete[] ptr;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" char* ptr = new char;\n"
|
||||
|
@ -2821,6 +2835,22 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("struct Fred { int i; };\n"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" Fred* ptr = new (nothrow ) Fred();\n"
|
||||
" delete ptr;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("struct Fred { int i; };\n"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" Fred* ptr = new (std::nothrow) Fred();\n"
|
||||
" delete ptr;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("struct Fred { int i; };\n"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue