Partial fix for #11378 internalAstError regressions (iscpp11init) (#4889)

This commit is contained in:
chrchr-github 2023-03-13 16:30:27 +01:00 committed by GitHub
parent 5721dca019
commit 322a1a5e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 12 deletions

View File

@ -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 "( ... )"

View File

@ -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

View File

@ -215,6 +215,7 @@ private:
/// @}
const Token* isLambdaCaptureList(const Token* tok);
const Token* findLambdaEndTokenWithoutAST(const Token* tok);
//---------------------------------------------------------------------------
#endif // tokenlistH

View File

@ -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() {