Fix #12249 Assert failure in ExpressionAnalyzer (II) (#5733)

This commit is contained in:
chrchr-github 2023-12-08 14:46:20 +01:00 committed by GitHub
parent 77d8eaa2a1
commit 7ac824f38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

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

View File

@ -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<void()>* p; };\n"
"S f() { return S{ std::make_unique<std::function<void()>>([]() {}).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<int>([]() { 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() {