diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 76133db55..1d7348009 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2591,8 +2591,13 @@ static void setVarIdClassDeclaration(Token * const startToken, ++indentlevel; } else if (tok->str() == "}") --indentlevel; - else if (tok->isName() && tok->varId() <= scopeStartVarId) { - if (indentlevel > 0 || (initList && indentlevel == 0 && (tok->strAt(-1) == "," || tok->strAt(-1) == ":"))) { + else if (initList && indentlevel == 0 && Token::Match(tok->previous(), "[,:] %var% (")) { + const std::map::const_iterator it = variableId.find(tok->str()); + if (it != variableId.end()) { + tok->varId(it->second); + } + } else if (tok->isName() && tok->varId() <= scopeStartVarId) { + if (indentlevel > 0) { if (Token::Match(tok->previous(), "::|.")) continue; if (tok->next()->str() == "::") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 35fd01a1e..b09580835 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4043,16 +4043,27 @@ private: void varid_initList() { - const char code[] = "class A {\n" - " A() : x(0) {}\n" - " int x;\n" - "};"; + const char code1[] = "class A {\n" + " A() : x(0) {}\n" + " int x;\n" + "};"; ASSERT_EQUALS("\n\n##file 0\n" "1: class A {\n" "2: A ( ) : x@1 ( 0 ) { }\n" "3: int x@1 ;\n" "4: } ;\n", - tokenizeDebugListing(code)); + tokenizeDebugListing(code1)); + + const char code2[] = "class A {\n" + " A(int x) : x(x) {}\n" + " int x;\n" + "};"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: class A {\n" + "2: A ( int x@1 ) : x@2 ( x@1 ) { }\n" + "3: int x@2 ;\n" + "4: } ;\n", + tokenizeDebugListing(code2)); } void varid_operator() {