Merge pull request #577 from Dmitry-Me/properSimplifyDeleteWithComma

Proper simplify delete a,b
This commit is contained in:
amai2012 2015-03-25 22:38:35 +01:00
commit c70db2a751
2 changed files with 12 additions and 3 deletions

View File

@ -8726,9 +8726,8 @@ void Tokenizer::simplifyComma()
if (Token::Match(tok->tokAt(-2), "delete %name% , %name% ;") && if (Token::Match(tok->tokAt(-2), "delete %name% , %name% ;") &&
tok->next()->varId() != 0) { tok->next()->varId() != 0) {
// Handle "delete a, b;" // Handle "delete a, b;" - convert to delete a; b;
tok->str(";"); tok->str(";");
tok->insertToken("delete");
} else if (!inReturn && tok->tokAt(-2)) { } else if (!inReturn && tok->tokAt(-2)) {
bool replace = false; bool replace = false;
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) { for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {

View File

@ -1796,7 +1796,17 @@ private:
" char *a, *b;\n" " char *a, *b;\n"
" delete a, b;\n" " delete a, b;\n"
"}\n"; "}\n";
ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; delete a ; delete b ; }", tok(code)); ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; delete a ; b ; }", tok(code));
}
{
const char code[] = "void foo()\n"
"{\n"
" char *a, *b;\n"
" if (x) \n"
" delete a, b;\n"
"}\n";
ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; if ( x ) { delete a ; b ; } }", tok(code));
} }
{ {