Fixed #645 (Tokenizer::simplifyCasts() breaks link() if casts function)

http://sourceforge.net/apps/trac/cppcheck/ticket/645
This commit is contained in:
Slava Semushin 2009-09-13 17:31:32 +07:00
parent dade31b6d7
commit 0fb89f8afa
2 changed files with 15 additions and 12 deletions

View File

@ -2263,19 +2263,12 @@ void Tokenizer::simplifyCasts()
if (Token::simpleMatch(tok2, "> ("))
{
Token::eraseTokens(tok, tok2->tokAt(2));
tok2 = tok;
int parlevel = 0;
while (tok2->next() && parlevel >= 0)
Token *closeBracket = tok2->next()->link();
if (closeBracket)
{
tok2 = tok2->next();
if (tok2->next()->str() == "(")
++parlevel;
else if (tok2->next()->str() == ")")
--parlevel;
Token::eraseTokens(tok, tok2->tokAt(2));
closeBracket->deleteThis();
}
if (tok2->next())
tok2->deleteNext();
}
}
}

View File

@ -672,8 +672,18 @@ private:
ASSERT_EQUALS(expected, sizeof_(code));
}
}
{
// ticket #645
const char code[] = "void f()\n"
"{\n"
" return dynamic_cast<Foo *>((bar()));\n"
"}\n";
const std::string expected(" void f ( ) { return bar ( ) ; }");
ASSERT_EQUALS(expected, sizeof_(code));
}
}