Fixed #8795 (Syntax Error: AST broken, binary operator '||' doesn't have two operands)

This commit is contained in:
Daniel Marjamäki 2019-05-04 19:05:03 +02:00
parent d0d671761a
commit 45a343ac2d
2 changed files with 8 additions and 2 deletions

View File

@ -586,6 +586,12 @@ static void compileTerm(Token *&tok, AST_state& state)
tok = tok->next();
if (tok->str() == "<")
tok = tok->link()->next();
if (Token::Match(tok, "{ . %name% =")) {
const bool inArrayAssignment = state.inArrayAssignment;
state.inArrayAssignment = true;
compileBinOp(tok, state, compileExpression);
state.inArrayAssignment = inArrayAssignment;
}
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
tok = skipDecl(tok);
while (tok->next() && tok->next()->isName())
@ -612,9 +618,8 @@ static void compileTerm(Token *&tok, AST_state& state)
compileUnaryOp(tok, state, compileExpression);
else
compileBinOp(tok, state, compileExpression);
if (Token::Match(tok, "} ,|:")) {
if (Token::Match(tok, "} ,|:"))
tok = tok->next();
}
} else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) {
state.op.push(tok);
tok = tok->link()->next();

View File

@ -7281,6 +7281,7 @@ private:
ASSERT_EQUALS("ac.0={(=", testAst("a = (b){.c=0,};")); // <- useless comma
ASSERT_EQUALS("xB[1y.z.1={(&=,{={=", testAst("x = { [B] = {1, .y = &(struct s) { .z=1 } } };"));
ASSERT_EQUALS("xab,c,{=", testAst("x={a,b,(c)};"));
ASSERT_EQUALS("x0fSa.1=b.2=,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = 1, .b = 2, .c = \"\" });"));
// struct initialization hang
ASSERT_EQUALS("sbar.1{,{(={= fcmd( forfieldfield++;;(",