Skip to content

Commit

Permalink
Fix #12249 Assert failure in ExpressionAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Dec 6, 2023
1 parent e766fba commit 8b02b36
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -1732,7 +1732,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
} else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
if (tok->tokType() == Token::Type::eBracket)
continue;
if (tok->astParent()->isAssignmentOp())
if (tok->astParent()->str() == "=")
continue;
if (tok->isControlFlowKeyword())
continue;
Expand Down
13 changes: 13 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid5);
TEST_CASE(exprid6);
TEST_CASE(exprid7);
TEST_CASE(exprid8);

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

void exprid8() {
const char code[] = "void f() {\n"
" std::string s;\n"
" (((s += \"--\") += std::string()) += \"=\");\n"
"}\n";
const char expected[] = "1: void f ( ) {\n"
"2: std ::@UNIQUE string s@1 ;\n"
"3: ( ( s@1 +=@UNIQUE \"--\"@UNIQUE ) +=@UNIQUE std ::@UNIQUE string (@UNIQUE ) ) +=@UNIQUE \"=\"@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 8b02b36

Please sign in to comment.