Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11488 FP unknownEvaluationOrder with designated initializers #7049

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading