diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 2eaf1e1b2..987131bdf 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -401,6 +401,12 @@ static bool iscast(const Token *tok) if (Token::Match(tok, "( (| typeof (") && Token::Match(tok->link(), ") %num%")) return true; + if (Token::Match(tok->link(), ") }|)|]")) + return false; + + if (Token::Match(tok->link(), ") %cop%") && !Token::Match(tok->link(), ") [&*+-~]")) + return false; + if (Token::Match(tok->previous(), "= ( %name% ) {") && tok->next()->varId() == 0) return true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1246d70a3..c08ae31ea 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8324,6 +8324,7 @@ private: ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};")); ASSERT_EQUALS("ac.0={(=", testAst("a = (b){.c=0,};")); // <- useless comma ASSERT_EQUALS("xB[1y.z.1={(&=,{={=", testAst("x = { [B] = {1, .y = &(struct s) { .z=1 } } };")); + ASSERT_EQUALS("xab,c,{=", testAst("x={a,b,(c)};")); // struct initialization hang ASSERT_EQUALS("sbar.1{,{(={= fcmd( forfieldfield++;;(",