From ac626a2426fe45687221fbf604ae017b005fc4f1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 13 May 2024 21:07:56 +0200 Subject: [PATCH] Fix #12713 Assert failure in ExpressionAnalyzer() (#6388) --- lib/symboldatabase.cpp | 2 +- test/testvarid.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index df786b608eb..998f24b7a30 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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 && diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 12695a2f038..ea8934b2403 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -248,6 +248,7 @@ class TestVarID : public TestFixture { TEST_CASE(exprid8); TEST_CASE(exprid9); TEST_CASE(exprid10); + TEST_CASE(exprid11); TEST_CASE(structuredBindings); } @@ -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(g({}, this)).release();\n" + " std::make_unique(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",