Fix ticket #418 (delete a,b; not tokenized correctly)

http://sourceforge.net/apps/trac/cppcheck/ticket/418
This commit is contained in:
Reijo Tomperi 2009-06-19 00:00:16 +03:00
parent b7171c3cd2
commit e8d1905e6d
2 changed files with 32 additions and 11 deletions

View File

@ -2976,11 +2976,21 @@ bool Tokenizer::simplifyCommaNearKeyWords()
// We must not accept just any keyword, e.g. accepting int
// would cause function parameters to corrupt.
if (!Token::Match(tok->next(), "delete"))
continue;
tok->str(";");
ret = true;
if (Token::Match(tok->next(), "delete"))
{
// Handle "delete a, delete b;"
tok->str(";");
ret = true;
}
else if (tok->previous() &&
Token::Match(tok->previous()->previous(), "delete") &&
tok->next()->varId() != 0)
{
// Handle "delete a, b;"
tok->str(";");
tok->insertToken("delete");
ret = true;
}
}
return ret;

View File

@ -978,12 +978,23 @@ private:
void comma_keyword()
{
const char code[] = "void foo()\n"
"{\n"
" char *a, *b;\n"
" delete a, delete b;\n"
"}\n";
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
{
const char code[] = "void foo()\n"
"{\n"
" char *a, *b;\n"
" delete a, delete b;\n"
"}\n";
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
}
{
const char code[] = "void foo()\n"
"{\n"
" char *a, *b;\n"
" delete a, b;\n"
"}\n";
ASSERT_EQUALS(" void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", sizeof_(code));
}
}
};