From 7ac824f38a700b3034fcae587640fa151c142b54 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:46:20 +0100 Subject: [PATCH] Fix #12249 Assert failure in ExpressionAnalyzer (II) (#5733) --- lib/symboldatabase.cpp | 2 +- test/testvarid.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 8422d534d..fa8dd86b0 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 42752d989..f9140fa42 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -3968,6 +3968,18 @@ private: "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 { std::function* p; };\n" + "S f() { return S{ std::make_unique>([]() {}).release()}; }"; + const char expected2[] = "1: struct S { std :: function < void ( ) > * p ; } ;\n" + "2: S f ( ) { return S@UNIQUE {@UNIQUE std ::@UNIQUE make_unique < std :: function < void ( ) > > (@UNIQUE [ ] ( ) { } ) .@UNIQUE release (@UNIQUE ) } ; }\n"; + ASSERT_EQUALS(expected2, tokenizeExpr(code2)); + + const char code3[] = "struct S { int* p; };\n" + "S f() { return S{ std::make_unique([]() { return 4; }()).release()}; }\n"; + const char expected3[] = "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(expected3, tokenizeExpr(code3)); } void structuredBindings() {