Skip to content

Commit 103ff90

Browse files
Fix #11572 Broken AST with brace-init and bitwise and (#4812)
1 parent e5a22e3 commit 103ff90

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/tokenlist.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,15 @@ static void compileScope(Token *&tok, AST_state& state)
934934
static bool isPrefixUnary(const Token* tok, bool cpp)
935935
{
936936
if (!tok->previous()
937-
|| ((Token::Match(tok->previous(), "(|[|{|%op%|;|}|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw"))
937+
|| ((Token::Match(tok->previous(), "(|[|{|%op%|;|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw"))
938938
&& (tok->previous()->tokType() != Token::eIncDecOp || tok->tokType() == Token::eIncDecOp)))
939939
return true;
940940

941+
if (tok->previous()->str() == "}") {
942+
const Token* parent = tok->linkAt(-1)->tokAt(-1);
943+
return !Token::Match(parent, "%type%") || parent->isKeyword();
944+
}
945+
941946
if (tok->str() == "*" && tok->previous()->tokType() == Token::eIncDecOp && isPrefixUnary(tok->previous(), cpp))
942947
return true;
943948

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6428,6 +6428,9 @@ class TestTokenizer : public TestFixture {
64286428
ASSERT_EQUALS("ab4<<c--+1:?", testAst("a ? (b << 4) + --c : 1"));
64296429
ASSERT_EQUALS("ab4<<c--+1:?", testAst("a ? (b << 4) + c-- : 1"));
64306430
ASSERT_EQUALS("ai[i= i--", testAst("a[i]=i; --i;"));
6431+
6432+
ASSERT_EQUALS("fint0{1&(", testAst("f(int{ 0 } & 1);")); // #11572
6433+
ASSERT_EQUALS("int0{1&return", testAst("int g() { return int{ 0 } & 1; }"));
64316434
}
64326435

64336436
void astfunction() { // function calls

0 commit comments

Comments
 (0)