Fixed ticket #572 (Tokenizer: improve detection of arrays)

http://sourceforge.net/apps/trac/cppcheck/ticket/572
This commit is contained in:
Slava Semushin 2009-08-09 15:16:37 +07:00
parent 5f3baba178
commit 1fd2c0ff28
2 changed files with 13 additions and 2 deletions

View File

@ -2326,12 +2326,14 @@ bool Tokenizer::simplifyVarDecl()
}
}
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,"))
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,") ||
Token::Match(tok2, "%type% %var% [ %var% ] ,"))
{
tok2 = tok2->tokAt(5); // The ',' token
}
else if (Token::Match(tok2, "%type% * %var% [ %num% ] ,"))
else if (Token::Match(tok2, "%type% * %var% [ %num% ] ,") ||
Token::Match(tok2, "%type% * %var% [ %var% ] ,"))
{
tok2 = tok2->tokAt(6); // The ',' token
}

View File

@ -1108,6 +1108,15 @@ private:
"}\n";
ASSERT_EQUALS(" void f ( ) { for ( int a , b ; a < 10 ; a = a + 1 , b = b + 1 ) { ; } }", sizeof_(code));
}
{
const char code[] = "void f()\n"
"{\n"
" char buf[BUFSIZ], **p;\n"
" char *ptrs[BUFSIZ], **pp;\n"
"}\n";
ASSERT_EQUALS(" void f ( ) { char buf [ BUFSIZ ] ; char * * p ; char * ptrs [ BUFSIZ ] ; char * * pp ; }", sizeof_(code));
}
}
void remove_comma()