From ef26b5573704568b2e58cc38860d7cdcb3d13d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Feb 2020 15:01:06 +0100 Subject: [PATCH] AST: Fix wrong handling for '{scope} (expr)' --- lib/tokenlist.cpp | 2 +- test/testtokenize.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0974de9d0..335f4ecb4 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -934,7 +934,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state) const std::size_t oldOpSize = state.op.size(); compileExpression(tok, state); tok = tok2; - if (Token::simpleMatch(tok->previous(), "} (") + if ((oldOpSize > 0 && Token::simpleMatch(tok->previous(), "} (")) || (tok->previous() && tok->previous()->isName() && !Token::Match(tok->previous(), "return|case") && (!state.cpp || !Token::Match(tok->previous(), "throw|delete"))) || (tok->strAt(-1) == "]" && (!state.cpp || !Token::Match(tok->linkAt(-1)->previous(), "new|delete"))) || (tok->strAt(-1) == ">" && tok->linkAt(-1)) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 85800bc5a..27e90def0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7672,6 +7672,7 @@ private: // Type{data}() ASSERT_EQUALS("ab{(=", testAst("a=b{}();")); ASSERT_EQUALS("abc{((=", testAst("a=b(c{}());")); + ASSERT_EQUALS("f( xNULL!=0(x(:?", testAst("void f() { {} ((x != NULL) ? (void)0 : x()); }")); // ({..}) ASSERT_EQUALS("a{+d+ bc+", testAst("a+({b+c;})+d"));