Fix #11572 Broken AST with brace-init and bitwise and (#4812)

This commit is contained in:
chrchr-github 2023-02-24 06:31:20 +01:00 committed by GitHub
parent e5a22e3436
commit 103ff907b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -6428,6 +6428,9 @@ private:
ASSERT_EQUALS("ab4<<c--+1:?", testAst("a ? (b << 4) + --c : 1"));
ASSERT_EQUALS("ab4<<c--+1:?", testAst("a ? (b << 4) + c-- : 1"));
ASSERT_EQUALS("ai[i= i--", testAst("a[i]=i; --i;"));
ASSERT_EQUALS("fint0{1&(", testAst("f(int{ 0 } & 1);")); // #11572
ASSERT_EQUALS("int0{1&return", testAst("int g() { return int{ 0 } & 1; }"));
}
void astfunction() { // function calls