Variable Id: structs must not have variable id

This commit is contained in:
Daniel Marjamäki 2009-05-31 18:46:32 +02:00
parent 5f57e4ac2d
commit 2120edb89b
2 changed files with 28 additions and 1 deletions

View File

@ -773,7 +773,7 @@ void Tokenizer::setVarId()
bool dot = false;
for (tok2 = tok->next(); tok2; tok2 = tok2->next())
{
if (!dot && tok2->str() == varname)
if (!dot && tok2->str() == varname && !Token::Match(tok2->previous(), "struct|union"))
tok2->varId(_varId);
else if (tok2->str() == "{")
++indentlevel;

View File

@ -107,6 +107,7 @@ private:
TEST_CASE(varidReturn);
TEST_CASE(varid8);
TEST_CASE(varid9);
TEST_CASE(varid10);
TEST_CASE(varidStl);
TEST_CASE(varid_delete);
TEST_CASE(varid_functions);
@ -1145,6 +1146,32 @@ private:
ASSERT_EQUALS(expected, actual);
}
void varid10()
{
const std::string code("void foo()\n"
"{\n"
" int abc;\n"
" struct abc abc1;\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 foo ( )\n"
"2: {\n"
"3: int abc@1 ;\n"
"4: struct abc abc1@2 ;\n"
"5: }\n");
ASSERT_EQUALS(expected, actual);
}
void varidStl()
{
const std::string code("list<int> ints;\n"