Skip to content

Commit

Permalink
Fix #11488 FP unknownEvaluationOrder with designated initializers (#7049
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chrchr-github authored Nov 29, 2024
1 parent 5c54e72 commit 1869eca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,8 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
continue;
if (tok->isControlFlowKeyword())
continue;
if (Token::Match(tok->tokAt(-1), ". %name%") && Token::Match(tok->tokAt(-2), "[{,]")) // designated initializers
continue;

if (Token::Match(tok, "%name% <") && tok->linkAt(1)) {
tok->exprId(id);
Expand Down
18 changes: 18 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid10);
TEST_CASE(exprid11);
TEST_CASE(exprid12);
TEST_CASE(exprid13);

TEST_CASE(structuredBindings);
}
Expand Down Expand Up @@ -4334,6 +4335,23 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(exp, tokenizeExpr(code));
}

void exprid13()
{
const char code[] = "struct S { int s; };\n" // #11488
"struct T { struct S s; };\n"
"struct U { struct T t; };\n"
"void f() {\n"
" struct U u = { .t = { .s = { .s = 1 } } };\n"
"}\n";
const char* exp = "1: struct S { int s ; } ;\n"
"2: struct T { struct S s ; } ;\n"
"3: struct U { struct T t ; } ;\n"
"4: void f ( ) {\n"
"5: struct U u@4 ; u@4 = { .@UNIQUE t@5 = { . s = { . s = 1 } } } ;\n"
"6: }\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 1869eca

Please sign in to comment.