Tokenizer: Don't treat typedefs as variable declarations (#234)

This commit is contained in:
Daniel Marjamäki 2009-03-28 21:07:33 +01:00
parent 4c4f138639
commit 6f7f8c4b4f
2 changed files with 21 additions and 1 deletions

View File

@ -623,7 +623,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "[,;{}(] %type%"))
tok = tok->next();
if (Token::Match(tok, "else|return"))
if (Token::Match(tok, "else|return|typedef"))
continue;
if (Token::simpleMatch(tok, "std ::"))

View File

@ -106,6 +106,7 @@ private:
TEST_CASE(varid7);
TEST_CASE(varidReturn);
TEST_CASE(varid8);
TEST_CASE(varid9);
TEST_CASE(file1);
TEST_CASE(file2);
@ -1029,6 +1030,25 @@ private:
ASSERT_EQUALS(expected, actual);
}
void varid9()
{
const std::string code("typedef int INT32;\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: typedef int INT32 ;\n");
ASSERT_EQUALS(expected, actual);
}