Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
d5d96d2535
|
@ -48,6 +48,9 @@ void CheckOther::WarningOldStylePointerCast()
|
||||||
if (!Token::Match(tok, "( %type% * ) %var%"))
|
if (!Token::Match(tok, "( %type% * ) %var%"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (Token::simpleMatch(tok->tokAt(4), "const"))
|
||||||
|
continue;
|
||||||
|
|
||||||
// Is "type" a class?
|
// Is "type" a class?
|
||||||
const std::string pattern("class " + tok->next()->str());
|
const std::string pattern("class " + tok->next()->str());
|
||||||
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||||
|
|
|
@ -2976,11 +2976,21 @@ bool Tokenizer::simplifyCommaNearKeyWords()
|
||||||
|
|
||||||
// We must not accept just any keyword, e.g. accepting int
|
// We must not accept just any keyword, e.g. accepting int
|
||||||
// would cause function parameters to corrupt.
|
// would cause function parameters to corrupt.
|
||||||
if (!Token::Match(tok->next(), "delete"))
|
if (Token::Match(tok->next(), "delete"))
|
||||||
continue;
|
{
|
||||||
|
// Handle "delete a, delete b;"
|
||||||
tok->str(";");
|
tok->str(";");
|
||||||
ret = true;
|
ret = true;
|
||||||
|
}
|
||||||
|
else if (tok->previous() &&
|
||||||
|
Token::Match(tok->previous()->previous(), "delete") &&
|
||||||
|
tok->next()->varId() != 0)
|
||||||
|
{
|
||||||
|
// Handle "delete a, b;"
|
||||||
|
tok->str(";");
|
||||||
|
tok->insertToken("delete");
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -58,6 +58,8 @@ private:
|
||||||
|
|
||||||
TEST_CASE(nullpointer1);
|
TEST_CASE(nullpointer1);
|
||||||
TEST_CASE(nullpointer2);
|
TEST_CASE(nullpointer2);
|
||||||
|
|
||||||
|
TEST_CASE(oldStylePointerCast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[])
|
void check(const char code[])
|
||||||
|
@ -427,6 +429,35 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkOldStylePointerCast(const char code[])
|
||||||
|
{
|
||||||
|
// Tokenize..
|
||||||
|
Tokenizer tokenizer;
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
tokenizer.setVarId();
|
||||||
|
|
||||||
|
// Clear the error buffer..
|
||||||
|
errout.str("");
|
||||||
|
|
||||||
|
// Check for redundant code..
|
||||||
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
|
checkOther.WarningOldStylePointerCast();
|
||||||
|
}
|
||||||
|
|
||||||
|
void oldStylePointerCast()
|
||||||
|
{
|
||||||
|
checkOldStylePointerCast("class B;\n"
|
||||||
|
"class A\n"
|
||||||
|
"{\n"
|
||||||
|
" virtual void abc(B *) const = 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestOther)
|
REGISTER_TEST(TestOther)
|
||||||
|
|
|
@ -978,12 +978,23 @@ private:
|
||||||
|
|
||||||
void comma_keyword()
|
void comma_keyword()
|
||||||
{
|
{
|
||||||
const char code[] = "void foo()\n"
|
{
|
||||||
"{\n"
|
const char code[] = "void foo()\n"
|
||||||
" char *a, *b;\n"
|
"{\n"
|
||||||
" delete a, delete b;\n"
|
" char *a, *b;\n"
|
||||||
"}\n";
|
" delete a, delete b;\n"
|
||||||
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
|
"}\n";
|
||||||
|
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char code[] = "void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *a, *b;\n"
|
||||||
|
" delete a, b;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue