Proper simplify delete a,b

This commit is contained in:
Dmitry-Me 2015-03-25 16:54:23 +03:00
parent 9846ff10b2
commit e8f0abf259
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% ;") &&
tok->next()->varId() != 0) {
// Handle "delete a, b;"
// Handle "delete a, b;" - convert to delete a; b;
tok->str(";");
tok->insertToken("delete");
} else if (!inReturn && tok->tokAt(-2)) {
bool replace = false;
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {

View File

@ -1796,7 +1796,17 @@ private:
" char *a, *b;\n"
" delete a, b;\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));
}
{