From ec61c6fa2650f27f57c0f92f3887a6ad679c3953 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 18 Jun 2010 07:16:05 +0200 Subject: [PATCH] Fixed #1801 (simplifyTypedef: duplicate typedefs not handled properly) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a01f6fb2a..fd01220ba 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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")))) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c56cc3571..93fbfa128 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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()