From 6e1cc11eff35f0ff4136a44074b67179ce1cf34f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 9 Mar 2023 20:01:06 +0100 Subject: [PATCH] Fix #11606 internalAstError with empty initializer list (#4875) --- lib/tokenlist.cpp | 11 ++++++----- test/testtokenize.cpp | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 6f12d39e5..ffcacf21f 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -483,12 +483,13 @@ static bool iscast(const Token *tok, bool cpp) const Token *tok3 = tok2->linkAt(1); while (tok3 != tok2 && Token::Match(tok3, "[{}]")) tok3 = tok3->previous(); - return tok3 != tok2 && tok3->str() != ";"; + return tok3->str() != ";"; } - return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || - (Token::Match(tok2, ") %any%") && - (!tok2->next()->isOp() || Token::Match(tok2->next(), "!|~|++|--")) && - !Token::Match(tok2->next(), "[[]);,?:.]")); + const bool res = type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || + (Token::Match(tok2, ") %any%") && + (!tok2->next()->isOp() || Token::Match(tok2->next(), "!|~|++|--")) && + !Token::Match(tok2->next(), "[[]);,?:.]")); + return res; } if (Token::Match(tok2, "&|&& )")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ee255ad16..9dfe3ea3c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6387,6 +6387,8 @@ private: ASSERT_EQUALS("xp(= 12>34:?", testAst("x = ( const char ( * ) [ 1 > 2 ? 3 : 4 ] ) p ;")); + ASSERT_EQUALS("f{(si.,(", testAst("f((struct S){ }, s->i);")); // #11606 + // not cast ASSERT_EQUALS("AB||", testAst("(A)||(B)")); ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;"));