Tokenizer::simplifyComma: dont simplify comma in '=(struct s){...}'

This commit is contained in:
Daniel Marjamäki 2017-04-26 20:48:08 +02:00
parent 4175902e36
commit bdf16b1157
2 changed files with 13 additions and 2 deletions

View File

@ -7912,12 +7912,17 @@ void Tokenizer::simplifyComma()
if (!tok)
syntaxError(nullptr); // invalid code like in #4195
if (Token::Match(tok, "(|[") ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) {
if (Token::Match(tok, "(|[") || Token::Match(tok->previous(), "%name%|= {")) {
tok = tok->link();
continue;
}
if (Token::simpleMatch(tok, "= (") && Token::simpleMatch(tok->linkAt(1), ") {")) {
tok = tok->linkAt(1)->linkAt(1);
continue;
}
// Skip unhandled template specifiers..
if (tok->link() && tok->str() == "<")
tok = tok->link();

View File

@ -1966,6 +1966,12 @@ private:
"}";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "tr = (struct reg){ .a = (1), .c = (2) };";
const char expected[] = "tr = ( struct reg ) { . a = 1 , . c = 2 } ;";
ASSERT_EQUALS(expected, tok(code));
}
}
void simplifyConditionOperator() {