Tokenizer: Fixed bad simplifyComma for code 'a ? b = c , d : e ;'

This commit is contained in:
Daniel Marjamäki 2014-04-17 18:47:55 +02:00
parent 8d5a9893d5
commit 064844f8db
2 changed files with 11 additions and 5 deletions

View File

@ -8540,17 +8540,18 @@ void Tokenizer::simplifyComma()
tok->str(";");
tok->insertToken("delete");
} else {
bool replace = false;
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {
if (tok2->str() == "=") {
// Handle "a = 0, b = 0;"
tok->str(";");
break;
replace = true;
} else if (Token::Match(tok2, "delete %var%") ||
Token::Match(tok2, "delete [ ] %var%")) {
// Handle "delete a, a = 0;"
tok->str(";");
break;
} else if (Token::Match(tok2, "[:;,{}()]")) {
replace = true;
} else if (Token::Match(tok2, "[?:;,{}()]")) {
if (replace && Token::Match(tok2, "[;{}]"))
tok->str(";");
break;
}
}

View File

@ -2894,6 +2894,11 @@ private:
ASSERT_EQUALS("void f ( ) { int a ; int b ; if ( a ) { a = 0 ; b = 0 ; } }", tok(code));
}
{
const char code[] = "a ? b = c , d : e ;"; // do nothing
ASSERT_EQUALS(code, tok(code));
}
{
const char code[] = "void f()\n"
"{\n"