Skip to content

Commit

Permalink
Fix #13123 VarID of a designated initializer (#7009)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 23, 2024
1 parent 64356ce commit ddc541b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4914,7 +4914,7 @@ void Tokenizer::setVarIdPass1()
}
}

if ((!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
if (tok->varId() == 0 && (!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
!Token::simpleMatch(tok->next(), ": ;")) {
const std::unordered_map<std::string, nonneg int>::const_iterator it = variableMap.map(globalNamespace).find(tok->str());
if (it != variableMap.map(globalNamespace).end()) {
Expand Down
9 changes: 9 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,15 @@ class TestVarID : public TestFixture {
tokenize("void foo() {\n"
" struct ABC abc = {.a { abc.a },.b= { abc.b } };\n"
"}"));

ASSERT_EQUALS("1: struct T { int a@1 ; } ;\n" // #13123
"2: void f ( int a@2 ) {\n"
"3: struct T t@3 ; t@3 = { . a@4 = 1 } ;\n"
"4: }\n",
tokenize("struct T { int a; };\n"
"void f(int a) {\n"
" struct T t = { .a = 1 };\n"
"}\n"));
}

void varid_arrayinit() {
Expand Down

0 comments on commit ddc541b

Please sign in to comment.