diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 608f05dc0..fc3a482c5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2962,15 +2962,20 @@ void Tokenizer::setVarId() } // constructor with initializer list - if (Token::Match(tok2, ") : %name% (|{")) { + if (Token::Match(tok2, ") : %name% (|{|<")) { Token *tok3 = tok2; do { Token *vartok = tok3->tokAt(2); std::map::const_iterator varpos = thisClassVars.find(vartok->str()); if (varpos != thisClassVars.end()) vartok->varId(varpos->second); - tok3 = vartok->linkAt(1); - } while (Token::Match(tok3, ")|} [:,] %name% (|{")); + if (vartok->strAt(1) == "<") { + tok3 = vartok->next()->findClosingBracket(); + if (tok3 && tok3->next()->link()) + tok3 = tok3->next()->link(); + } else + tok3 = vartok->linkAt(1); + } while (Token::Match(tok3, ")|} [:,] %name% (|{|<")); if (Token::Match(tok3, ")|} {")) { setVarIdClassFunction(classname, tok2, tok3->next()->link(), thisClassVars, structMembers, &_varId); } diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 5dd455d4c..38b16c7f2 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -1859,6 +1859,23 @@ private: "3: A ( int x@2 ) : x@1 ( x@2 ) { }\n" "4: } ;\n", tokenize(code4)); + + const char code5[] = "class BCLass : public Ticket {\n" + " BCLass();\n" + " PClass* member;\n" + "};\n" + "BCLass::BCLass() : Ticket() {\n" + " member = 0;\n" + "}"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: class BCLass : public Ticket < void > {\n" + "2: BCLass ( ) ;\n" + "3: PClass * member@1 ;\n" + "4: } ;\n" + "5: BCLass :: BCLass ( ) : Ticket < void > ( ) {\n" + "6: member@1 = 0 ;\n" + "7: }\n", + tokenize(code5)); } void varid_operator() {