diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 6d2f143d1..c5d4d1bab 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -489,6 +489,8 @@ struct AST_state { explicit AST_state(bool cpp) : depth(0), inArrayAssignment(0), cpp(cpp), assign(0), inCase(false),stopAtColon(false), functionCallEndPar(nullptr) {} }; +static Token * createAstAtToken(Token *tok, bool cpp); + static Token* skipDecl(Token* tok, std::vector* inner = nullptr) { if (!Token::Match(tok->previous(), "( %name%")) @@ -974,6 +976,9 @@ static void compilePrecedence2(Token *&tok, AST_state& state) squareBracket->astOperand1(roundBracket); roundBracket->astOperand1(curlyBracket); state.op.push(squareBracket); + for (tok = roundBracket->next(); precedes(tok, roundBracket->link()); tok = tok->next()) { + tok = createAstAtToken(tok, state.cpp); + } tok = curlyBracket->link()->next(); continue; } @@ -1361,8 +1366,6 @@ static bool isLambdaCaptureList(const Token * tok) return true; } -static Token * createAstAtToken(Token *tok, bool cpp); - // Compile inner expressions inside inner ({..}) and lambda bodies static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0fb27a9bb..8b8873518 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6469,6 +6469,9 @@ private: " const auto y = z;\n" " switch (y) {}\n" "};")); + + // #10831 + ASSERT_EQUALS("f{([= x{([=", testAst("void foo() { F f = [](t x = []() {}) {}; }")); } void astcase() {