From 4aaa314eba14501536fa39e223cd02b046ce771f Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 7 Dec 2023 00:43:03 +0100 Subject: [PATCH] Fix #12249 Assert failure in ExpressionAnalyzer (II) --- lib/symboldatabase.cpp | 2 +- test/testvarid.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 8422d534d3b..fa8dd86b06a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1588,7 +1588,7 @@ namespace { if (op1 && op1->exprId() == 0) return; const Token* op2 = tok->astParent()->astOperand2(); - if (op2 && op2->exprId() == 0) + if (op2 && op2->exprId() == 0 && !(isLambdaCaptureList(op2) || (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())))) return; if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 42752d98906..d1284882e30 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -3968,6 +3968,12 @@ class TestVarID : public TestFixture { "3: ( ( s@1 +=@UNIQUE \"--\"@UNIQUE ) +=@UNIQUE std ::@UNIQUE string (@UNIQUE ) ) +=@UNIQUE \"=\"@UNIQUE ;\n" "4: }\n"; ASSERT_EQUALS(expected, tokenizeExpr(code)); + + const char code2[] = "struct S { int* p; };\n" + "S f() { return S{ std::make_unique([]() { return 4; }()).release()}; }\n"; + const char expected2[] = "1: struct S { int * p ; } ;\n" + "2: S f ( ) { return S@UNIQUE {@UNIQUE std ::@UNIQUE make_unique < int > (@UNIQUE [ ] ( ) { return 4 ; } ( ) ) .@UNIQUE release (@UNIQUE ) } ; }\n"; + ASSERT_EQUALS(expected2, tokenizeExpr(code2)); } void structuredBindings() {