Fixed ticket #584 (Tokenizer: don't set varId for class declaration)

http://sourceforge.net/apps/trac/cppcheck/ticket/584
This commit is contained in:
Slava Semushin 2009-08-12 01:58:49 +07:00
parent e7feac506c
commit 6a7624054e
2 changed files with 20 additions and 1 deletions

View File

@ -742,7 +742,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "[,;{}(] %type%"))
tok = tok->next();
if (Token::Match(tok, "else|return|typedef|delete"))
if (Token::Match(tok, "else|return|typedef|delete|class"))
continue;
if (Token::Match(tok, "const|static|extern|public:|private:|protected:"))

View File

@ -93,6 +93,7 @@ private:
TEST_CASE(varid8);
TEST_CASE(varid9);
TEST_CASE(varid10);
TEST_CASE(varid11);
TEST_CASE(varidStl);
TEST_CASE(varid_delete);
TEST_CASE(varid_functions);
@ -1270,6 +1271,24 @@ private:
ASSERT_EQUALS(expected, actual);
}
void varid11()
{
const std::string code("class Foo;\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");
ASSERT_EQUALS(expected, actual);
}
void varidStl()
{
const std::string code("list<int> ints;\n"