Remove unnecessaryForwardDeclaration check. It had false positives (e.g. #3663), was implemented in the Tokenizer and of little value.

This commit is contained in:
Alexander Mai 2016-01-02 19:14:03 +01:00
parent db6dfa2d22
commit ce12e1cea6
3 changed files with 12 additions and 57 deletions

View File

@ -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<const Token*> 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<std::string>& 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");
}

View File

@ -718,11 +718,6 @@ private:
bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef, const std::set<std::string>& 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<unsigned int, std::map<std::string,unsigned int> >& 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.
*/

View File

@ -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<std::string, int> 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
{