From b3856cbc5e369d50f1916fe1c0033cef73ba6ff4 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 17 Mar 2010 17:31:08 +0100 Subject: [PATCH] Fixed #1506 (typedef name hiding check combined with forward declaration leeds to false positive) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9f2d27d6f..199f8fbe9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -494,7 +494,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) // look backwards if (Token::Match(tok->previous(), "typedef|}|>") || (Token::Match(tok->previous(), "%type%") && - (!Token::Match(tok->previous(), "return|new|const|friend") && + (!Token::Match(tok->previous(), "return|new|const|friend|struct") && !Token::Match(tok->tokAt(-2), "friend class")))) { // scan backwards for the end of the previous statement diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e479d702c..c1754b5e0 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -180,6 +180,7 @@ private: TEST_CASE(simplifyTypedef39); TEST_CASE(simplifyTypedef40); TEST_CASE(simplifyTypedef41); // ticket #1488 + TEST_CASE(simplifyTypedef42); // ticket #1506 TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -3531,6 +3532,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef42() + { + // ticket #1506 + checkSimplifyTypedef("typedef struct A { } A;\n" + "struct A;"); + ASSERT_EQUALS("", errout.str()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));