Skip to content

Commit

Permalink
Fix #12450 Assert failure in ExpressionAnalyzer()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 17, 2024
1 parent d145f9c commit fa428ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,10 @@ namespace {
return;
const Token* op2 = tok->astParent()->astOperand2();
if (op2 && op2->exprId() == 0 &&
!(isLambdaCaptureList(op2) || (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || Token::simpleMatch(op2, "{ }")))
!((tok->astParent()->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->astParent()->isAssignmentOp()) ||
isLambdaCaptureList(op2) ||
(op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) ||
Token::simpleMatch(op2, "{ }")))
return;

if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) {
Expand Down
14 changes: 14 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid7);
TEST_CASE(exprid8);
TEST_CASE(exprid9);
TEST_CASE(exprid10);

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

void exprid10()
{
const char code[] = "void f(const std::string& p) {\n" // #12350
" std::string s;\n"
" ((s = \"abc\") += p) += \"def\";\n"
"}\n";
const char expected[] = "1: void f ( const std :: string & p ) {\n"
"2: std ::@UNIQUE string s@2 ;\n"
"3: ( ( s@2 =@UNIQUE \"abc\" ) +=@UNIQUE p@1 ) +=@UNIQUE \"def\"@UNIQUE ;\n"
"4: }\n";
ASSERT_EQUALS(expected, 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 fa428ef

Please sign in to comment.