Fixed #1801 (simplifyTypedef: duplicate typedefs not handled properly)

This commit is contained in:
Robert Reif 2010-06-18 07:16:05 +02:00 committed by Daniel Marjamäki
parent 0c61454b3f
commit ec61c6fa26
2 changed files with 16 additions and 1 deletions

View File

@ -548,7 +548,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
else
{
// look backwards
if (Token::Match(tok->previous(), "typedef|}|>") ||
if (Token::Match(tok->previous(), "typedef|}|>|*") ||
(Token::Match(tok->previous(), "%type%") &&
(!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected") &&
!Token::Match(tok->tokAt(-2), "friend class"))))

View File

@ -4189,6 +4189,21 @@ private:
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);\n"
"typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);\n";
checkSimplifyTypedef(code);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) Typedef 'PPDMarkOption' hides typedef with same name\n", errout.str());
}
{
const char code[] = "typedef int * A;\n"
"typedef int * A;\n";
checkSimplifyTypedef(code);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) Typedef 'A' hides typedef with same name\n", errout.str());
}
}
void simplifyTypedefFunction1()