diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c00d98e47ac..d76209d79a0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4912,7 +4912,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::const_iterator it = variableMap.map(globalNamespace).find(tok->str()); if (it != variableMap.map(globalNamespace).end()) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index d25681f407e..206ab7efab6 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -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() {