From 76c28073aa061b8304770952b5314bc4d91b1148 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:55:55 +0100 Subject: [PATCH] Revert fix for #10831 (#4631) --- lib/symboldatabase.cpp | 13 ++++++++++++- lib/tokenlist.cpp | 7 ++----- test/testtokenize.cpp | 15 ++++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ef3811dbb..3be12c9d1 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4062,6 +4062,17 @@ static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* //--------------------------------------------------------------------------- +static const Token* findLambdaEndTokenWithoutAST(const Token* tok) { + if (!(Token::simpleMatch(tok, "[") && tok->link())) + return nullptr; + tok = tok->link()->next(); + if (Token::simpleMatch(tok, "(") && tok->link()) + tok = tok->link()->next(); + if (!(Token::simpleMatch(tok, "{") && tok->link())) + return nullptr; + return tok->link()->next(); +}; + void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope) { // check for non-empty argument list "( ... )" @@ -4185,7 +4196,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s initArgCount++; if (tok->strAt(1) == "[") { const Token* lambdaStart = tok->next(); - tok = findLambdaEndToken(lambdaStart); + tok = type == eLambda ? findLambdaEndTokenWithoutAST(lambdaStart) : findLambdaEndToken(lambdaStart); if (!tok) throw InternalError(lambdaStart, "Analysis failed (lambda not recognized). If the code is valid then please report this failure.", InternalError::INTERNAL); } diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 088582f23..92bb1f7db 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -489,8 +489,6 @@ 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) { auto isDecltypeFuncParam = [](const Token* tok) -> bool { @@ -1008,9 +1006,6 @@ 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; } @@ -1406,6 +1401,8 @@ const Token* isLambdaCaptureList(const Token * tok) return params->astOperand1(); } +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 dfb01f8d7..ba1e51c26 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6243,10 +6243,6 @@ private: ASSERT_EQUALS("decltypexy+(yx+{", testAst("decltype(x+y){y+x};")); ASSERT_EQUALS("adecltypeac::(,decltypead::(,", testAst("template void b(a &, decltype(a::c), decltype(a::d));")); - ASSERT_EQUALS("g{([= decltypea0[(", - testAst("auto g = [](decltype(a[0]) i) {};")); - ASSERT_EQUALS("g{([= decltypea0[(i&", - testAst("auto g = [](decltype(a[0])& i) {};")); ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n" // #10839 "struct B { A* hash; };\n" @@ -6281,6 +6277,14 @@ private: " for (int i = 0; i <= 123; ++i)\n" " x->emplace_back(y);\n" "}"); + + ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #10831 + " auto g = [](std::function h = []() {}) { };\n" + "}")); + + ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #11379 + " auto l = [x = 3](std::string&& v) { };\n" + "}\n")); } void astbrackets() { // [] @@ -6505,9 +6509,6 @@ private: " switch (y) {}\n" "};")); - // #10831 - ASSERT_EQUALS("f{([= x{([=", testAst("void foo() { F f = [](t x = []() {}) {}; }")); - // #11357 ASSERT_NO_THROW(tokenizeAndStringify("void f(std::vector& v, bool c) {\n" " std::sort(v.begin(), v.end(), [&c](const auto a, const auto b) {\n"