Fixed #696 (Tokenizer: Simplify array declaration)

http://sourceforge.net/apps/trac/cppcheck/ticket/696
This commit is contained in:
Slava Semushin 2009-09-20 17:28:15 +07:00
parent 003e27c10e
commit 58a9e05697
2 changed files with 19 additions and 2 deletions

View File

@ -2502,10 +2502,18 @@ void Tokenizer::simplifyVarDecl()
}
}
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,") ||
Token::Match(tok2, "%type% %var% [ %var% ] ,"))
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,|=") ||
Token::Match(tok2, "%type% %var% [ %var% ] ,|="))
{
tok2 = tok2->tokAt(5); // The ',' token
if (tok2->str() == "=")
{
while (tok2 && tok2->str() != ",")
{
tok2 = tok2->next();
}
}
}
else if (Token::Match(tok2, "%type% * %var% [ %num% ] ,") ||

View File

@ -139,6 +139,7 @@ private:
TEST_CASE(vardecl5);
TEST_CASE(vardecl6);
TEST_CASE(vardecl7);
TEST_CASE(vardecl8);
TEST_CASE(vardecl_stl);
TEST_CASE(volatile_variables);
TEST_CASE(syntax_error);
@ -2236,6 +2237,14 @@ private:
ASSERT_EQUALS(res, tokenizeAndStringify(code));
}
void vardecl8()
{
// ticket #696
const char code[] = "char a[10]={'\\0'}, b[10]={'\\0'};";
const char res[] = "char a [ 10 ] = { '\\0' } ; char b [ 10 ] = { '\\0' } ;";
ASSERT_EQUALS(res, tokenizeAndStringify(code));
}
void volatile_variables()
{