From c572e6af87f7d302258d5075ad4c8c64fb7028d4 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 13 Jul 2010 08:08:12 +0200 Subject: [PATCH] Fixed #1846 (False positive with -s: Variable hides typedef with same name) --- lib/tokenize.cpp | 3 ++- test/testsimplifytokens.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 429291dcb..2fb66ac58 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -555,7 +555,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) else { // look backwards - if (Token::Match(tok->previous(), "typedef|}|>|*") || + if (Token::Match(tok->previous(), "typedef|}|>") || + (tok->previous()->str() == "*" && tok->next()->str() != "(") || (Token::Match(tok->previous(), "%type%") && (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") && !Token::Match(tok->tokAt(-2), "friend class")))) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9ae5bab5c..3bee07ea8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -207,6 +207,7 @@ private: TEST_CASE(simplifyTypedef54); // ticket #1814 TEST_CASE(simplifyTypedef55); TEST_CASE(simplifyTypedef56); // ticket #1829 + TEST_CASE(simplifyTypedef57); // ticket #1846 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4268,6 +4269,25 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef57() // ticket #1846 + { + const char code[] = "void foo {\n" + " typedef int A;\n" + " A a = A(1) * A(2);\n" + "};\n"; + + // The expected result.. + const std::string expected("void foo { " + "; " + "int a ; a = int ( 1 ) * int ( 2 ) ; " + "} ;"); + ASSERT_EQUALS(expected, sizeof_(code)); + + // Check for output.. + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {