fix #2864 (--errorlist missing errors: variableHidingTypedef and Extra qualification)

This commit is contained in:
Robert Reif 2011-06-28 21:46:54 -04:00
parent f403de7bad
commit 1286898fa0
2 changed files with 81 additions and 43 deletions

View File

@ -486,10 +486,13 @@ void Tokenizer::createTokens(std::istream &code)
void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, const std::string &type)
{
if (!(_settings->_checkCodingStyle))
if (tok1 && !(_settings->_checkCodingStyle))
return;
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
std::string tok2_str;
if (tok1 && tok2)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok1->linenr();
loc.setfile(file(tok1));
@ -497,10 +500,14 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons
loc.line = tok2->linenr();
loc.setfile(file(tok2));
locationList.push_back(loc);
tok2_str = tok2->str();
}
else
tok2_str = "name";
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::style,
std::string(type + " '" + tok2->str() +
std::string(type + " '" + tok2_str +
"' hides typedef with same name"),
"variableHidingTypedef",
false);
@ -513,10 +520,13 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons
void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2, const std::string &type)
{
if (!(_settings->_checkCodingStyle))
if (tok1 && !(_settings->_checkCodingStyle))
return;
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
std::string tok2_str;
if (tok1 && tok2)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok1->linenr();
loc.setfile(file(tok1));
@ -524,10 +534,14 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2,
loc.line = tok2->linenr();
loc.setfile(file(tok2));
locationList.push_back(loc);
tok2_str = tok2->str();
}
else
tok2_str = "name";
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::style,
std::string(type + " '" + tok2->str() +
std::string(type + " '" + tok2_str +
"' forward declaration unnecessary, already declared"),
"unnecessaryForwardDeclaration",
false);
@ -7878,10 +7892,13 @@ void Tokenizer::simplifyNestedStrcat()
void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const std::string & type)
{
if (!(_settings->_checkCodingStyle))
if (tok1 && !(_settings->_checkCodingStyle))
return;
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
std::string tok2_str;
if (tok1 && tok2)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok1->linenr();
loc.setfile(file(tok1));
@ -7889,10 +7906,14 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const
loc.line = tok2->linenr();
loc.setfile(file(tok2));
locationList.push_back(loc);
tok2_str = tok2->str();
}
else
tok2_str = "name";
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::style,
std::string(type + " '" + tok2->str() +
std::string(type + " '" + tok2_str +
"' hides enumerator with same name"),
"variableHidingEnum",
false);
@ -9083,6 +9104,10 @@ void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *setti
Tokenizer t(settings, errorLogger);
t.syntaxError(0, ' ');
t.cppcheckError(0);
t.duplicateTypedefError(0, 0, "Variable");
t.duplicateDeclarationError(0, 0, "Variable");
t.duplicateEnumError(0, 0, "Variable");
t.unnecessaryQualificationError(0, "type");
}
/** find pattern */
@ -9869,28 +9894,36 @@ void Tokenizer::removeUnnecessaryQualification()
continue;
}
unnecessaryQualificationError(tok, qualification);
tok->deleteThis();
tok->deleteThis();
}
}
}
}
void Tokenizer::unnecessaryQualificationError(const Token *tok, const std::string &qualification)
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
if (tok)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();
loc.setfile(file(tok));
locationList.push_back(loc);
}
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::portability,
"Extra qualification \'" + qualification + "\' unnecessary and considered an error by many compilers.",
"portability",
"unnecessaryQualification",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else
Check::reportError(errmsg);
tok->deleteThis();
tok->deleteThis();
}
}
}
}
void Tokenizer::simplifyReturn()

View File

@ -591,6 +591,11 @@ public:
*/
void removeUnnecessaryQualification();
/**
* unnecessary member qualification error
*/
void unnecessaryQualificationError(const Token *tok, const std::string &qualification);
/**
* Remove Microsoft MFC 'DECLARE_MESSAGE_MAP()'
*/