Improve C style pointer cast detection
http://sourceforge.net/apps/trac/cppcheck/ticket/724
This commit is contained in:
parent
68d2b3c86c
commit
16e55f4f89
|
@ -45,7 +45,8 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Old style pointer casting..
|
// Old style pointer casting..
|
||||||
if (!Token::Match(tok, "( const| %type% * ) %var%"))
|
if (!Token::Match(tok, "( const| %type% * ) %var%") &&
|
||||||
|
!Token::Match(tok, "( const| %type% * ) (| new"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int addToIndex = 0;
|
int addToIndex = 0;
|
||||||
|
|
|
@ -782,6 +782,27 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
|
checkOldStylePointerCast("class Base;\n"
|
||||||
|
"void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" Base * b = (const Base *) ( new Derived() );\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
|
checkOldStylePointerCast("class Base;\n"
|
||||||
|
"void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" Base * b = (const Base *) new Derived();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
|
checkOldStylePointerCast("class Base;\n"
|
||||||
|
"void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" Base * b = (const Base *) new short[10];\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
checkOldStylePointerCast("class B;\n"
|
checkOldStylePointerCast("class B;\n"
|
||||||
"class A\n"
|
"class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue