From 103ff907b62a16df8733e7fb9b085090161809a6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 24 Feb 2023 06:31:20 +0100 Subject: [PATCH] Fix #11572 Broken AST with brace-init and bitwise and (#4812) --- lib/tokenlist.cpp | 7 ++++++- test/testtokenize.cpp | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 380446b32..a2f44f2ca 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -934,10 +934,15 @@ static void compileScope(Token *&tok, AST_state& state) static bool isPrefixUnary(const Token* tok, bool cpp) { if (!tok->previous() - || ((Token::Match(tok->previous(), "(|[|{|%op%|;|}|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw")) + || ((Token::Match(tok->previous(), "(|[|{|%op%|;|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw")) && (tok->previous()->tokType() != Token::eIncDecOp || tok->tokType() == Token::eIncDecOp))) return true; + if (tok->previous()->str() == "}") { + const Token* parent = tok->linkAt(-1)->tokAt(-1); + return !Token::Match(parent, "%type%") || parent->isKeyword(); + } + if (tok->str() == "*" && tok->previous()->tokType() == Token::eIncDecOp && isPrefixUnary(tok->previous(), cpp)) return true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c7ba4c68f..dfa0f57e8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6428,6 +6428,9 @@ private: ASSERT_EQUALS("ab4<