Skip to content

Commit ac626a2

Browse files
Fix #12713 Assert failure in ExpressionAnalyzer() (#6388)
1 parent 6875514 commit ac626a2

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ namespace {
15701570
if (!tok->astParent() || tok->astParent()->isControlFlowKeyword())
15711571
return;
15721572
const Token* op1 = tok->astParent()->astOperand1();
1573-
if (op1 && op1->exprId() == 0)
1573+
if (op1 && op1->exprId() == 0 && !Token::Match(op1, "[{[]"))
15741574
return;
15751575
const Token* op2 = tok->astParent()->astOperand2();
15761576
if (op2 && op2->exprId() == 0 &&

test/testvarid.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class TestVarID : public TestFixture {
248248
TEST_CASE(exprid8);
249249
TEST_CASE(exprid9);
250250
TEST_CASE(exprid10);
251+
TEST_CASE(exprid11);
251252

252253
TEST_CASE(structuredBindings);
253254
}
@@ -4169,6 +4170,26 @@ class TestVarID : public TestFixture {
41694170
ASSERT_EQUALS(expected, tokenizeExpr(code));
41704171
}
41714172

4173+
void exprid11()
4174+
{
4175+
const char* code{}, *exp{};
4176+
code = "struct S { void f(); };\n" // #12713
4177+
"int g(int, S*);\n"
4178+
"int h(void (*)(), S*);\n"
4179+
"void S::f() {\n"
4180+
" std::make_unique<int>(g({}, this)).release();\n"
4181+
" std::make_unique<int>(h([]() {}, this)).release();\n"
4182+
"}\n";
4183+
exp = "1: struct S { void f ( ) ; } ;\n"
4184+
"2: int g ( int , S * ) ;\n"
4185+
"3: int h ( void ( * ) ( ) , S * ) ;\n"
4186+
"4: void S :: f ( ) {\n"
4187+
"5: std ::@UNIQUE make_unique < int > (@UNIQUE g (@UNIQUE { } ,@6 this ) ) .@UNIQUE release (@UNIQUE ) ;\n"
4188+
"6: std ::@UNIQUE make_unique < int > (@UNIQUE h (@UNIQUE [ ] ( ) { } ,@6 this ) ) .@UNIQUE release (@UNIQUE ) ;\n"
4189+
"7: }\n";
4190+
ASSERT_EQUALS(exp, tokenizeExpr(code));
4191+
}
4192+
41724193
void structuredBindings() {
41734194
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
41744195
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)