diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a43e23f91..0aa0ee7c5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -581,7 +581,11 @@ static void compileTerm(Token *&tok, AST_state& state) tok = tok->next(); if (state.inArrayAssignment && tok->str() == "." && Token::Match(tok->previous(), ",|{")) // Jump over . in C style struct initialization tok = tok->next(); - + if (state.inArrayAssignment && Token::Match(tok->previous(), "[,{] [ %num% ]")) { + state.op.push(tok); + tok->astOperand1(tok->next()); + tok = tok->tokAt(3); + } if (tok->isLiteral()) { state.op.push(tok); do { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 58ed76be0..2ae5a19b6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8070,6 +8070,7 @@ private: 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 ASSERT_EQUALS("sbar1{,{(={= fcmd( forfieldfield++;;(",