diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index dcbe69299..041576b54 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -475,6 +475,9 @@ static bool iscast(const Token *tok) if (Token::Match(tok, "( (| typeof (") && Token::Match(tok->link(), ") %num%")) return true; + if (Token::Match(tok->previous(), "= ( %name% ) {") && tok->next()->varId() == 0) + return true; + bool type = false; for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { while (tok2->link() && Token::Match(tok2, "(|[|<")) @@ -620,11 +623,14 @@ static void compileTerm(Token *&tok, AST_state& state) } } } else if (tok->str() == "{") { + const Token *prev = tok->previous(); + if (prev && prev->str() == ")") + prev = prev->link()->previous(); if (Token::simpleMatch(tok->link(),"} [")) { tok = tok->next(); } else if (tok->previous() && tok->previous()->isName()) { compileBinOp(tok, state, compileExpression); - } else if (!state.inArrayAssignment && tok->strAt(-1) != "=") { + } else if (!state.inArrayAssignment && (!prev || prev->str() != "=")) { state.op.push(tok); tok = tok->link()->next(); } else { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 31564835f..5243ceff5 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8076,7 +8076,6 @@ private: ASSERT_EQUALS("ab2[a0=b0=,{a0=b0=,{,{=", testAst("struct AB ab[2] = { { .a=0, .b=0 }, { .a=0, .b=0 } };")); ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};")); ASSERT_EQUALS("s1a&,{2b&,{,{=", testAst("s = { {1, &a}, {2, &b} };")); - TODO_ASSERT_EQUALS("xatoistr({(=", "x{(= atoistr(", testAst("x = (struct X){atoi(str)};")); ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};")); // struct initialization hang @@ -8162,6 +8161,8 @@ private: ASSERT_EQUALS("ab-(=", testAst("a = ((int)-b)")); // Multiple subsequent unary operators (cast and -) ASSERT_EQUALS("xdouble123(i*(=", testAst("x = (int)(double(123)*i);")); ASSERT_EQUALS("ac(=", testAst("a = (::b)c;")); + ASSERT_EQUALS("abcd,({(=", testAst("a = (s){b(c, d)};")); + ASSERT_EQUALS("xatoistr({(=", testAst("x = (struct X){atoi(str)};")); // not cast ASSERT_EQUALS("AB||", testAst("(A)||(B)"));