Skip to content

Commit

Permalink
Fix #12713 Assert failure in ExpressionAnalyzer() (danmar#6388)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 13, 2024
1 parent 6875514 commit ac626a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ namespace {
if (!tok->astParent() || tok->astParent()->isControlFlowKeyword())
return;
const Token* op1 = tok->astParent()->astOperand1();
if (op1 && op1->exprId() == 0)
if (op1 && op1->exprId() == 0 && !Token::Match(op1, "[{[]"))
return;
const Token* op2 = tok->astParent()->astOperand2();
if (op2 && op2->exprId() == 0 &&
Expand Down
21 changes: 21 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid8);
TEST_CASE(exprid9);
TEST_CASE(exprid10);
TEST_CASE(exprid11);

TEST_CASE(structuredBindings);
}
Expand Down Expand Up @@ -4169,6 +4170,26 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, tokenizeExpr(code));
}

void exprid11()
{
const char* code{}, *exp{};
code = "struct S { void f(); };\n" // #12713
"int g(int, S*);\n"
"int h(void (*)(), S*);\n"
"void S::f() {\n"
" std::make_unique<int>(g({}, this)).release();\n"
" std::make_unique<int>(h([]() {}, this)).release();\n"
"}\n";
exp = "1: struct S { void f ( ) ; } ;\n"
"2: int g ( int , S * ) ;\n"
"3: int h ( void ( * ) ( ) , S * ) ;\n"
"4: void S :: f ( ) {\n"
"5: std ::@UNIQUE make_unique < int > (@UNIQUE g (@UNIQUE { } ,@6 this ) ) .@UNIQUE release (@UNIQUE ) ;\n"
"6: std ::@UNIQUE make_unique < int > (@UNIQUE h (@UNIQUE [ ] ( ) { } ,@6 this ) ) .@UNIQUE release (@UNIQUE ) ;\n"
"7: }\n";
ASSERT_EQUALS(exp, tokenizeExpr(code));
}

void structuredBindings() {
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",
Expand Down

0 comments on commit ac626a2

Please sign in to comment.