errmsg: Added 'unused struct member'

This commit is contained in:
Daniel Marjamäki 2009-01-12 17:21:25 +00:00
parent 15a32103e2
commit a0ef840138
4 changed files with 15 additions and 6 deletions

View File

@ -700,9 +700,7 @@ void CheckOther::CheckStructMemberUsage()
if (! used)
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next()) << ": struct or union member '" << structname << "::" << varname << "' is never used";
_errorLogger->reportErr(errmsg.str());
_errorLogger->reportErr(ErrorMessage::unusedStructMember(_tokenizer, tok->next(), structname, varname));
}
}
}

View File

@ -319,6 +319,10 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorMessage::ifNoAction(_settings))
checkOther.WarningIf();
// Unused struct members..
if (ErrorMessage::unusedStructMember(_settings))
checkOther.CheckStructMemberUsage();
if (_settings._checkCodingStyle)
{
@ -328,9 +332,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Check if a constant function parameter is passed by value
checkOther.CheckConstantFunctionParameter();
// Unused struct members..
checkOther.CheckStructMemberUsage();
// Check for various types of incomplete statements that could for example
// mean that an ';' has been added by accident
checkOther.CheckIncompleteStatement();

View File

@ -219,5 +219,14 @@ public:
return s._showAll & s._checkCodingStyle;
}
static std::string unusedStructMember(const Tokenizer *tokenizer, const Token *Location, const std::string &structname, const std::string &varname)
{
return msg1(tokenizer, Location) + "struct or union member '" + structname + "::" + varname + "' is never used";
}
static bool unusedStructMember(const Settings &s)
{
return s._checkCodingStyle;
}
};
#endif

View File

@ -83,6 +83,7 @@ int main()
err.push_back(Message("sprintfOverlappingData", 0, "Overlapping data buffer %1", "varname"));
err.push_back(Message("udivError", 0, "Unsigned division. The result will be wrong."));
err.push_back(Message("udivWarning", Message::STYLE | Message::ALL, "Warning: Division with signed and unsigned operators"));
err.push_back(Message("unusedStructMember", Message::STYLE, "struct or union member '%1::%2' is never used", "structname", "varname"));
// Generate code..
std::cout << "Generate code.." << std::endl;