From 322a1a5e8c4fc8988870136c26660845122f07bf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 13 Mar 2023 16:30:27 +0100 Subject: [PATCH] Partial fix for #11378 internalAstError regressions (iscpp11init) (#4889) --- lib/symboldatabase.cpp | 11 ----------- lib/tokenlist.cpp | 13 ++++++++++++- lib/tokenlist.h | 1 + test/testtokenize.cpp | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1ff598483..bc8a926e6 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4128,17 +4128,6 @@ 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 "( ... )" diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 7e322f797..e9d4bba80 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -878,7 +878,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state) tok = tok->previous(); return !Token::Match(tok, "new ::| %type%"); } - return true; + return !findLambdaEndTokenWithoutAST(tok); }; if (doCompileScope(tok)) @@ -1327,6 +1327,17 @@ const Token* isLambdaCaptureList(const Token * tok) return params->astOperand1(); } +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(); +} + static Token * createAstAtToken(Token *tok, bool cpp); // Compile inner expressions inside inner ({..}) and lambda bodies diff --git a/lib/tokenlist.h b/lib/tokenlist.h index ed7b7bffe..68b14523d 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -215,6 +215,7 @@ private: /// @} const Token* isLambdaCaptureList(const Token* tok); +const Token* findLambdaEndTokenWithoutAST(const Token* tok); //--------------------------------------------------------------------------- #endif // tokenlistH diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 758590203..52b960ed7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6542,6 +6542,8 @@ private: // #11378 ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };")); + + ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }")); } void astcase() {