From 45a343ac2d27a4ee12debb3948131a8ba70b422c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 4 May 2019 19:05:03 +0200 Subject: [PATCH] Fixed #8795 (Syntax Error: AST broken, binary operator '||' doesn't have two operands) --- lib/tokenlist.cpp | 9 +++++++-- test/testtokenize.cpp | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 3abb0161c..300c590c6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 24b1a07d1..99022fd44 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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++;;(",