diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 42d50f63571..f5e7f8bd511 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4617,8 +4617,9 @@ void Tokenizer::setVarIdPass1() if (!(scopeStack.top().isStructInit || tok->strAt(-1) == "=")) variableMap.enterScope(); } + const bool isStructInit = scopeStack.top().isStructInit || tok->strAt(-1) == "=" || (initlist && !Token::Match(tok->tokAt(-1), "[)}]")); + scopeStack.emplace(isExecutable, isStructInit, isEnumStart(tok), variableMap.getVarId()); initlist = false; - scopeStack.emplace(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), variableMap.getVarId()); } else { /* if (tok->str() == "}") */ bool isNamespace = false; for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 02ea62f6f3d..6399f2a1405 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2508,6 +2508,16 @@ class TestVarID : public TestFixture { "5: A :: A ( const Matrix & m@3 ) throw ( e ) : work@1 ( 0 )\n" "6: { }\n", tokenize(code10)); + + const char code11[] = "struct S {\n" // #12733 + " explicit S(int& r) : a{ int{ 1 } }, b{ r } {}\n" + " int a, &b;\n" + "};"; + ASSERT_EQUALS("1: struct S {\n" + "2: explicit S ( int & r@1 ) : a@2 { int { 1 } } , b@3 { r@1 } { }\n" + "3: int a@2 ; int & b@3 ;\n" + "4: } ;\n", + tokenize(code11)); } void varid_initListWithBaseTemplate() {