Fix ticket 308 (cppcheck msg:: invalid number of ((). Cant process file)
This commit is contained in:
parent
3d592baeb0
commit
e89c03da92
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue