Fixed ticket #278 (variable id: references are not handled correctly)

http://sourceforge.net/apps/trac/cppcheck/ticket/278
This commit is contained in:
Slava Semushin 2009-06-18 23:30:04 +07:00
parent 269e823c63
commit fafc261611
2 changed files with 44 additions and 1 deletions

View File

@ -734,6 +734,9 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "else|return|typedef|delete"))
continue;
if (Token::simpleMatch(tok, "const"))
tok = tok->next();
if (Token::simpleMatch(tok, "std ::"))
tok = tok->tokAt(2);
@ -759,7 +762,7 @@ void Tokenizer::setVarId()
{
if (tok2->isName())
varname = tok2->strAt(0);
else if (tok2->str() != "*")
else if (tok2->str() != "*" && tok2->str() != "&")
break;
tok2 = tok2->next();
}

View File

@ -1291,6 +1291,46 @@ private:
ASSERT_EQUALS(expected, actual);
}
{
const std::string code("void f1(int &p)\n"
"{\n"
" p = 0;\n"
"}\n"
"void f2(std::string &str)\n"
"{\n"
" str.clear();\n"
"}\n"
"void f3(const std::string &s)\n"
"{\n"
" s.size();\n"
"}\n");
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
// result..
const std::string actual(tokenizer.tokens()->stringifyList(true));
const std::string expected("\n\n##file 0\n"
"1: void f1 ( int & p@1 )\n"
"2: {\n"
"3: p@1 = 0 ;\n"
"4: }\n"
"5: void f2 ( std :: string & str@2 )\n"
"6: {\n"
"7: str@2 . clear ( ) ;\n"
"8: }\n"
"9: void f3 ( const std :: string & s@3 )\n"
"10: {\n"
"11: s@3 . size ( ) ;\n"
"12: }\n");
ASSERT_EQUALS(expected, actual);
}
}
void varidclass1()