Skip to content

Commit 322a1a5

Browse files
Partial fix for #11378 internalAstError regressions (iscpp11init) (#4889)
1 parent 5721dca commit 322a1a5

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,17 +4128,6 @@ static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase*
41284128

41294129
//---------------------------------------------------------------------------
41304130

4131-
static const Token* findLambdaEndTokenWithoutAST(const Token* tok) {
4132-
if (!(Token::simpleMatch(tok, "[") && tok->link()))
4133-
return nullptr;
4134-
tok = tok->link()->next();
4135-
if (Token::simpleMatch(tok, "(") && tok->link())
4136-
tok = tok->link()->next();
4137-
if (!(Token::simpleMatch(tok, "{") && tok->link()))
4138-
return nullptr;
4139-
return tok->link()->next();
4140-
}
4141-
41424131
void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope)
41434132
{
41444133
// check for non-empty argument list "( ... )"

lib/tokenlist.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
878878
tok = tok->previous();
879879
return !Token::Match(tok, "new ::| %type%");
880880
}
881-
return true;
881+
return !findLambdaEndTokenWithoutAST(tok);
882882
};
883883

884884
if (doCompileScope(tok))
@@ -1327,6 +1327,17 @@ const Token* isLambdaCaptureList(const Token * tok)
13271327
return params->astOperand1();
13281328
}
13291329

1330+
const Token* findLambdaEndTokenWithoutAST(const Token* tok) {
1331+
if (!(Token::simpleMatch(tok, "[") && tok->link()))
1332+
return nullptr;
1333+
tok = tok->link()->next();
1334+
if (Token::simpleMatch(tok, "(") && tok->link())
1335+
tok = tok->link()->next();
1336+
if (!(Token::simpleMatch(tok, "{") && tok->link()))
1337+
return nullptr;
1338+
return tok->link()->next();
1339+
}
1340+
13301341
static Token * createAstAtToken(Token *tok, bool cpp);
13311342

13321343
// Compile inner expressions inside inner ({..}) and lambda bodies

lib/tokenlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class CPPCHECKLIB TokenList {
215215
/// @}
216216

217217
const Token* isLambdaCaptureList(const Token* tok);
218+
const Token* findLambdaEndTokenWithoutAST(const Token* tok);
218219

219220
//---------------------------------------------------------------------------
220221
#endif // tokenlistH

test/testtokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6542,6 +6542,8 @@ class TestTokenizer : public TestFixture {
65426542

65436543
// #11378
65446544
ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };"));
6545+
6546+
ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }"));
65456547
}
65466548

65476549
void astcase() {

0 commit comments

Comments
 (0)