Fixed ticket #574 (Tokenizer: not assign varId when variable first afer keyword and has long type)

http://sourceforge.net/apps/trac/cppcheck/ticket/574
This commit is contained in:
Slava Semushin 2009-08-09 15:41:31 +07:00
parent 1fd2c0ff28
commit c66103f7bc
2 changed files with 30 additions and 1 deletions

View File

@ -745,7 +745,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "else|return|typedef|delete"))
continue;
if (Token::Match(tok, "const|static|extern"))
if (Token::Match(tok, "const|static|extern|public:|private:|protected:"))
tok = tok->next();
while (Token::Match(tok, "%var% ::"))

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(varid_delete);
TEST_CASE(varid_functions);
TEST_CASE(varid_reference_to_containers);
TEST_CASE(varid_in_class);
TEST_CASE(varidclass1);
TEST_CASE(varidclass2);
@ -1444,6 +1445,34 @@ private:
ASSERT_EQUALS(expected, actual);
}
void varid_in_class()
{
const std::string code("class Foo\n"
"{\n"
"public:\n"
" std::string name1;\n"
" std::string name2;\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: class Foo\n"
"2: {\n"
"3: public:\n"
"4: std :: string name1@1 ;\n"
"5: std :: string name2@2 ;\n"
"6: } ;\n");
ASSERT_EQUALS(expected, actual);
}
void varidclass1()
{
const std::string code("class Fred\n"