Fix #487 (Tokenizer: Simplify sizeof for string array and string pointer)
http://sourceforge.net/apps/trac/cppcheck/ticket/487
This commit is contained in:
parent
8472e58413
commit
06dd66bff4
|
@ -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())
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue