Skip to content

Commit 7ac824f

Browse files
Fix #12249 Assert failure in ExpressionAnalyzer (II) (#5733)
1 parent 77d8eaa commit 7ac824f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ namespace {
15881588
if (op1 && op1->exprId() == 0)
15891589
return;
15901590
const Token* op2 = tok->astParent()->astOperand2();
1591-
if (op2 && op2->exprId() == 0)
1591+
if (op2 && op2->exprId() == 0 && !(isLambdaCaptureList(op2) || (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1()))))
15921592
return;
15931593

15941594
if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) {

test/testvarid.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,18 @@ class TestVarID : public TestFixture {
39683968
"3: ( ( s@1 +=@UNIQUE \"--\"@UNIQUE ) +=@UNIQUE std ::@UNIQUE string (@UNIQUE ) ) +=@UNIQUE \"=\"@UNIQUE ;\n"
39693969
"4: }\n";
39703970
ASSERT_EQUALS(expected, tokenizeExpr(code));
3971+
3972+
const char code2[] = "struct S { std::function<void()>* p; };\n"
3973+
"S f() { return S{ std::make_unique<std::function<void()>>([]() {}).release()}; }";
3974+
const char expected2[] = "1: struct S { std :: function < void ( ) > * p ; } ;\n"
3975+
"2: S f ( ) { return S@UNIQUE {@UNIQUE std ::@UNIQUE make_unique < std :: function < void ( ) > > (@UNIQUE [ ] ( ) { } ) .@UNIQUE release (@UNIQUE ) } ; }\n";
3976+
ASSERT_EQUALS(expected2, tokenizeExpr(code2));
3977+
3978+
const char code3[] = "struct S { int* p; };\n"
3979+
"S f() { return S{ std::make_unique<int>([]() { return 4; }()).release()}; }\n";
3980+
const char expected3[] = "1: struct S { int * p ; } ;\n"
3981+
"2: S f ( ) { return S@UNIQUE {@UNIQUE std ::@UNIQUE make_unique < int > (@UNIQUE [ ] ( ) { return 4 ; } ( ) ) .@UNIQUE release (@UNIQUE ) } ; }\n";
3982+
ASSERT_EQUALS(expected3, tokenizeExpr(code3));
39713983
}
39723984

39733985
void structuredBindings() {

0 commit comments

Comments
 (0)