From ce12e1cea633ec0e7022867df19833a4793f722a Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 2 Jan 2016 19:14:03 +0100 Subject: [PATCH] Remove unnecessaryForwardDeclaration check. It had false positives (e.g. #3663), was implemented in the Tokenizer and of little value. --- lib/tokenize.cpp | 21 --------------------- lib/tokenize.h | 30 ++++++++++++------------------ test/testsimplifytypedef.cpp | 18 ------------------ 3 files changed, 12 insertions(+), 57 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 02dd8adbc..c82a5bce5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -209,20 +209,6 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons std::string("The " + type + " '" + tok2_str + "' hides a typedef with the same name."), true); } -void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2, const std::string &type) const -{ - if (tok1 && !(_settings->isEnabled("style"))) - return; - - std::list locationList; - locationList.push_back(tok1); - locationList.push_back(tok2); - const std::string tok2_str = tok2 ? tok2->str() : std::string("name"); - - reportError(locationList, Severity::style, "unnecessaryForwardDeclaration", - std::string("The " + type + " '" + tok2_str + "' forward declaration is unnecessary. Type " + type + " is already declared earlier.")); -} - // check if this statement is a duplicate definition bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef, const std::set& structs) const { @@ -330,8 +316,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token duplicateTypedefError(*tokPtr, name, "struct"); return true; } else { - // forward declaration after declaration - duplicateDeclarationError(*tokPtr, name, "struct"); return false; } } else if (tok->previous()->str() == "union") { @@ -339,8 +323,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token duplicateTypedefError(*tokPtr, name, "union"); return true; } else { - // forward declaration after declaration - duplicateDeclarationError(*tokPtr, name, "union"); return false; } } else if (isCPP() && tok->previous()->str() == "class") { @@ -348,8 +330,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token duplicateTypedefError(*tokPtr, name, "class"); return true; } else { - // forward declaration after declaration - duplicateDeclarationError(*tokPtr, name, "class"); return false; } } @@ -8746,7 +8726,6 @@ void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *setti { Tokenizer t(settings, errorLogger); t.duplicateTypedefError(0, 0, "variable"); - t.duplicateDeclarationError(0, 0, "variable"); t.duplicateEnumError(0, 0, "variable"); } diff --git a/lib/tokenize.h b/lib/tokenize.h index 9d84a6096..7f2d9c3e0 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -718,11 +718,6 @@ private: bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef, const std::set& structs) const; void duplicateTypedefError(const Token *tok1, const Token *tok2, const std::string & type) const; - /** - * Report error - duplicate declarations - */ - void duplicateDeclarationError(const Token *tok1, const Token *tok2, const std::string &type) const; - void unsupportedTypedef(const Token *tok) const; void setVarIdClassDeclaration(Token * const startToken, @@ -730,6 +725,18 @@ private: const unsigned int scopeStartVarId, std::map >& structMembers); + + /** + * Simplify e.g. 'return(strncat(temp,"a",1));' into + * strncat(temp,"a",1); return temp; + */ + void simplifyReturnStrncat(); + + /** + * Output list of unknown types. + */ + void printUnknownTypes() const; + public: /** Was there templates in the code? */ @@ -768,19 +775,6 @@ public: return _varId; } - - /** - * Simplify e.g. 'return(strncat(temp,"a",1));' into - * strncat(temp,"a",1); return temp; - */ - void simplifyReturnStrncat(); - - /** - * Output list of unknown types. - */ - void printUnknownTypes() const; - - /** * Token list: stores all tokens. */ diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 771dce77f..ea69d450c 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -78,7 +78,6 @@ private: TEST_CASE(simplifyTypedef39); TEST_CASE(simplifyTypedef40); TEST_CASE(simplifyTypedef41); // ticket #1488 - TEST_CASE(simplifyTypedef42); // ticket #1506 TEST_CASE(simplifyTypedef43); // ticket #1588 TEST_CASE(simplifyTypedef44); TEST_CASE(simplifyTypedef45); // ticket #1613 @@ -1209,23 +1208,6 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef42() { - // ticket #1506 - checkSimplifyTypedef("typedef struct A { } A;\n" - "struct A;"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) The struct 'A' forward declaration is unnecessary. Type struct is already declared earlier.\n", errout.str()); - - checkSimplifyTypedef("typedef union A { int i; float f; } A;\n" - "union A;"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) The union 'A' forward declaration is unnecessary. Type union is already declared earlier.\n", errout.str()); - - const char code [] = "typedef std::map A;\n" - "class A;"; - checkSimplifyTypedef(code); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) The class 'A' forward declaration is unnecessary. Type class is already declared earlier.\n", errout.str()); - TODO_ASSERT_EQUALS("class A ;", "class std :: map < std :: string , int > ;", tok(code)); - } - void simplifyTypedef43() { // ticket #1588 {