Fix #487 (Tokenizer: Simplify sizeof for string array and string pointer)

http://sourceforge.net/apps/trac/cppcheck/ticket/487
This commit is contained in:
Reijo Tomperi 2009-10-07 11:08:53 +03:00
parent 8472e58413
commit 06dd66bff4
2 changed files with 11 additions and 11 deletions

View File

@ -608,16 +608,6 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
// remove exception specifications.. // remove exception specifications..
removeExceptionSpecifications(_tokens); removeExceptionSpecifications(_tokens);
// change array to pointer..
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
{
Token::eraseTokens(tok->next(), tok->tokAt(4));
tok->insertToken("*");
}
}
setVarId(); setVarId();
return true; return true;
@ -1730,6 +1720,16 @@ void Tokenizer::simplifyTokenList()
simplifySizeof(); simplifySizeof();
// change array to pointer..
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
{
Token::eraseTokens(tok->next(), tok->tokAt(4));
tok->insertToken("*");
}
}
// Replace constants.. // Replace constants..
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {

View File

@ -673,7 +673,7 @@ private:
std::ostringstream expected; std::ostringstream expected;
expected << "; const char * str ; str = \"1\" ; " << sizeof(str) << " ;"; expected << "; const char * str ; str = \"1\" ; " << sizeof(str) << " ;";
TODO_ASSERT_EQUALS(expected.str(), sizeof_(code)); ASSERT_EQUALS(expected.str(), sizeof_(code));
} }
{ {