errmsg: Added "found redundant if - 'if (condition);'

This commit is contained in:
Daniel Marjamäki 2009-01-12 06:44:47 +00:00
parent 153487d504
commit ae861852e2
4 changed files with 16 additions and 4 deletions

View File

@ -214,7 +214,7 @@ void CheckOther::WarningIf()
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Found \"if (condition);\"";
_errorLogger->reportErr(ostr.str());
_errorLogger->reportErr(ErrorMessage::ifNoAction(_tokenizer, tok));
}
break;
}

View File

@ -312,11 +312,13 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorMessage::operatorEq(_settings))
checkClass.operatorEq();
if (_settings._checkCodingStyle)
{
// if (condition);
// if (condition);
if (ErrorMessage::ifNoAction(_settings))
checkOther.WarningIf();
if (_settings._checkCodingStyle)
{
// Variable scope (check if the scope could be limited)
//CheckVariableScope();

View File

@ -183,5 +183,14 @@ public:
return true;
}
static std::string ifNoAction(const Tokenizer *tokenizer, const Token *Location)
{
return msg1(tokenizer, Location) + "Found redundant if condition - 'if (condition);'";
}
static bool ifNoAction(const Settings &s)
{
return s._checkCodingStyle;
}
};
#endif

View File

@ -79,6 +79,7 @@ int main()
err.push_back(Message("redundantIfDelete0", Message::STYLE, "Redundant condition. It is safe to deallocate a NULL pointer"));
err.push_back(Message("redundantIfRemove", Message::STYLE, "Redundant condition. The remove function in the STL will not do anything if element doesn't exist"));
err.push_back(Message("dangerousUsageStrtol", 0, "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36"));
err.push_back(Message("ifNoAction", Message::STYLE, "Found redundant if condition - 'if (condition);'"));
// Generate code..
std::cout << "Generate code.." << std::endl;