errmsg: Added "operator= should return something

This commit is contained in:
Daniel Marjamäki 2009-01-10 17:57:31 +00:00
parent 1fc5f5485f
commit 6acb123f1d
4 changed files with 22 additions and 13 deletions

View File

@ -650,11 +650,10 @@ void CheckClass::noMemset()
void CheckClass::operatorEq() void CheckClass::operatorEq()
{ {
if (const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (")) const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (");
if (tok)
{ {
std::ostringstream ostr; _errorLogger->reportErr(ErrorMessage::operatorEq(_tokenizer, tok));
ostr << _tokenizer->fileLine(tok) << ": 'operator=' should return something";
_errorLogger->reportErr(ostr.str());
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -310,12 +310,12 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorMessage::unusedPrivateFunction(_settings)) if (ErrorMessage::unusedPrivateFunction(_settings))
checkClass.privateFunctions(); checkClass.privateFunctions();
// 'operator=' should return something..
if (ErrorMessage::operatorEq(_settings))
checkClass.operatorEq();
if (_settings._checkCodingStyle) if (_settings._checkCodingStyle)
{ {
checkClass.operatorEq();
// if (condition); // if (condition);
checkOther.WarningIf(); checkOther.WarningIf();

View File

@ -57,24 +57,33 @@ public:
return s._checkCodingStyle; return s._checkCodingStyle;
} }
static std::string memsetClass(const Tokenizer *tokenizer, const Token *Location, const std::string &funcname) static std::string memsetClass(const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc)
{ {
return msg1(tokenizer, Location) + "Using '" + funcname + "' on class"; return msg1(tokenizer, Location) + "Using '" + memfunc + "' on class";
} }
static bool memsetClass(const Settings &s) static bool memsetClass(const Settings &s)
{ {
return true; return true;
} }
static std::string memsetStruct(const Tokenizer *tokenizer, const Token *Location, const std::string &funcname, const std::string &classname) static std::string memsetStruct(const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc, const std::string &classname)
{ {
return msg1(tokenizer, Location) + "Using '" + funcname + "' on struct that contains a 'std::" + classname + "'"; return msg1(tokenizer, Location) + "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'";
} }
static bool memsetStruct(const Settings &s) static bool memsetStruct(const Settings &s)
{ {
return true; return true;
} }
static std::string operatorEq(const Tokenizer *tokenizer, const Token *Location)
{
return msg1(tokenizer, Location) + "'operator=' should return something";
}
static bool operatorEq(const Settings &s)
{
return s._checkCodingStyle;
}
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
return msg1(tokenizer, Location) + "Memory leak: " + varname + ""; return msg1(tokenizer, Location) + "Memory leak: " + varname + "";

View File

@ -57,8 +57,9 @@ int main()
err.push_back(Message("noConstructor", Message::STYLE, "The class '%1' has no constructor", "classname")); err.push_back(Message("noConstructor", Message::STYLE, "The class '%1' has no constructor", "classname"));
err.push_back(Message("uninitVar", 0, "Uninitialized member variable '%1::%2'", "classname", "varname")); err.push_back(Message("uninitVar", 0, "Uninitialized member variable '%1::%2'", "classname", "varname"));
err.push_back(Message("unusedPrivateFunction", Message::STYLE, "Unused private function '%1::%2'", "classname", "funcname")); err.push_back(Message("unusedPrivateFunction", Message::STYLE, "Unused private function '%1::%2'", "classname", "funcname"));
err.push_back(Message("memsetClass", 0, "Using '%1' on class", "funcname")); err.push_back(Message("memsetClass", 0, "Using '%1' on class", "memfunc"));
err.push_back(Message("memsetStruct", 0, "Using '%1' on struct that contains a 'std::%2'", "funcname", "classname")); err.push_back(Message("memsetStruct", 0, "Using '%1' on struct that contains a 'std::%2'", "memfunc", "classname"));
err.push_back(Message("operatorEq", Message::STYLE, "'operator=' should return something"));
// checkmemoryleak.cpp.. // checkmemoryleak.cpp..
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname")); err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));