From e8ed8434e6420a69c9169d674590b3cf2cb00974 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:50:32 +0100 Subject: [PATCH 1/3] Update testvarid.cpp --- test/testvarid.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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() { From df341558dd243d146333ded7e8bc1f5d3c688366 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:52:05 +0100 Subject: [PATCH 2/3] Update tokenize.cpp --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c00d98e47ac..5ee9f083991 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4915,7 +4915,7 @@ void Tokenizer::setVarIdPass1() if ((!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()) { + if (it != variableMap.map(globalNamespace).end() && tok->varId() == 0) { tok->varId(it->second); setVarIdStructMembers(tok, structMembers, variableMap.getVarId()); } From 67701928d32698a76c1dafa617e3f527b81aa7de Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:43:51 +0100 Subject: [PATCH 3/3] Update tokenize.cpp --- lib/tokenize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5ee9f083991..d76209d79a0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4912,10 +4912,10 @@ 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() && tok->varId() == 0) { + if (it != variableMap.map(globalNamespace).end()) { tok->varId(it->second); setVarIdStructMembers(tok, structMembers, variableMap.getVarId()); }