Fix ticket 308 (cppcheck msg:: invalid number of ((). Cant process file)

This commit is contained in:
Daniel Marjamäki 2009-05-27 20:06:19 +02:00
parent 3d592baeb0
commit e89c03da92
2 changed files with 32 additions and 1 deletions

View File

@ -1776,8 +1776,20 @@ bool Tokenizer::simplifyCasts()
else if (Token::Match(tok->next(), "dynamic_cast|reinterpret_cast|const_cast|static_cast <"))
{
while (tok->next() && tok->next()->str() != ">")
unsigned int level = 0;
while (tok->next())
{
const Token *next = tok->next();
if (next->str() == "<")
++level;
else if (next->str() == ">")
{
--level;
if (level == 0)
break;
}
tok->deleteNext();
}
tok->deleteNext();
tok->deleteNext();
Token *tok2 = tok;

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(longtok);
TEST_CASE(removeCast1);
TEST_CASE(removeCast2);
TEST_CASE(inlineasm);
@ -228,6 +229,24 @@ private:
ASSERT_EQUALS(std::string(" int * f ( int * ) ;"), ostr.str());
}
// remove static_cast..
void removeCast2()
{
const char code[] = "t = (static_cast<std::vector<int> *>(&p));\n";
// tokenize..
OurTokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyCasts();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" t = ( & p ) ;"), ostr.str());
}
void inlineasm()
{