Tokenizer::setVarId: Fixed problem with initializer lists (#4436)

This commit is contained in:
Daniel Marjamäki 2012-12-27 18:15:00 +01:00
parent a43ae677d7
commit bf9b900c30
2 changed files with 18 additions and 2 deletions

View File

@ -2818,7 +2818,7 @@ void Tokenizer::setVarId()
std::map<std::string, unsigned int> varlist;
const Token* tokStart = Token::findsimplematch(tok, "{");
if (tokStart) {
for (const Token *tok2 = tokStart->next(); tok2 != tok->link(); tok2 = tok2->next()) {
for (const Token *tok2 = tokStart->next(); tok2 != tokStart->link(); tok2 = tok2->next()) {
// skip parentheses..
if (tok2->str() == "{")
tok2 = tok2->link();
@ -2866,8 +2866,11 @@ void Tokenizer::setVarId()
// constructor with initializer list
if (Token::Match(tok2, ") : %var% (")) {
const Token *tok3 = tok2;
Token *tok3 = tok2;
while (Token::Match(tok3, ") [:,] %var% (")) {
Token *vartok = tok3->tokAt(2);
if (varlist.find(vartok->str()) != varlist.end())
vartok->varId(varlist[vartok->str()]);
tok3 = tok3->linkAt(3);
}
if (Token::simpleMatch(tok3, ") {")) {

View File

@ -4067,6 +4067,19 @@ private:
"3: int x@2 ;\n"
"4: } ;\n",
tokenizeDebugListing(code2));
const char code3[] = "class A {\n"
" A(int x);\n"
" int x;\n"
"};\n"
"A::A(int x) : x(x) {}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: A ( int x@1 ) ;\n"
"3: int x@2 ;\n"
"4: } ;\n"
"5: A :: A ( int x@3 ) : x@2 ( x@3 ) { }\n",
tokenizeDebugListing(code3));
}
void varid_operator() {