Skip to content

Commit ddc541b

Browse files
Fix #13123 VarID of a designated initializer (danmar#7009)
1 parent 64356ce commit ddc541b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4914,7 +4914,7 @@ void Tokenizer::setVarIdPass1()
49144914
}
49154915
}
49164916

4917-
if ((!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
4917+
if (tok->varId() == 0 && (!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
49184918
!Token::simpleMatch(tok->next(), ": ;")) {
49194919
const std::unordered_map<std::string, nonneg int>::const_iterator it = variableMap.map(globalNamespace).find(tok->str());
49204920
if (it != variableMap.map(globalNamespace).end()) {

test/testvarid.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,15 @@ class TestVarID : public TestFixture {
31253125
tokenize("void foo() {\n"
31263126
" struct ABC abc = {.a { abc.a },.b= { abc.b } };\n"
31273127
"}"));
3128+
3129+
ASSERT_EQUALS("1: struct T { int a@1 ; } ;\n" // #13123
3130+
"2: void f ( int a@2 ) {\n"
3131+
"3: struct T t@3 ; t@3 = { . a@4 = 1 } ;\n"
3132+
"4: }\n",
3133+
tokenize("struct T { int a; };\n"
3134+
"void f(int a) {\n"
3135+
" struct T t = { .a = 1 };\n"
3136+
"}\n"));
31283137
}
31293138

31303139
void varid_arrayinit() {

0 commit comments

Comments
 (0)