From 584a4280252b2dbca59b414be5d132d81a1d2b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 10 Oct 2022 21:05:27 +0200 Subject: [PATCH] Fixed #10831 ("Analysis failed (lambda not recognized)" with lamba default parameter in lambda signature) --- lib/tokenlist.cpp | 7 +++++-- test/testtokenize.cpp | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) 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() {