errmsg: Added message for 'incomplete statement'

This commit is contained in:
Daniel Marjamäki 2009-01-12 17:46:24 +00:00
parent a5eb8894d4
commit fdf5b215f9
4 changed files with 17 additions and 7 deletions

View File

@ -783,13 +783,12 @@ void CheckOther::CheckIncompleteStatement()
if ((tok->str() != "#") && Token::Match(tok->next(), "; %str%") && !Token::Match(tok->tokAt(3), ","))
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next()) << ": Redundant code: Found a statement that begins with string constant";
_errorLogger->reportErr(errmsg.str());
_errorLogger->reportErr(ErrorMessage::constStatement(_tokenizer, tok->next(), "string"));
}
if (!Token::Match(tok, "#") && Token::Match(tok->next(), "; %num%") && !Token::Match(tok->tokAt(3), ","))
{
_errorLogger->reportErr(ErrorMessage::constStatement(_tokenizer, tok->next(), "numeric"));
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next()) << ": Redundant code: Found a statement that begins with numeric constant";
_errorLogger->reportErr(errmsg.str());

View File

@ -339,11 +339,12 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
{
// Variable scope (check if the scope could be limited)
//CheckVariableScope();
}
// Check for various types of incomplete statements that could for example
// mean that an ';' has been added by accident
if (ErrorMessage::constStatement(_settings))
checkOther.CheckIncompleteStatement();
}
}
//---------------------------------------------------------------------------

View File

@ -273,5 +273,14 @@ public:
return s._checkCodingStyle;
}
static std::string constStatement(const Tokenizer *tokenizer, const Token *Location, const std::string &type)
{
return msg1(tokenizer, Location) + "Redundant code: Found a statement that begins with " + type + " constant";
}
static bool constStatement(const Settings &s)
{
return s._checkCodingStyle;
}
};
#endif

View File

@ -89,6 +89,7 @@ int main()
err.push_back(Message("unusedVariable", Message::STYLE, "Unused variable '%1'", "varname"));
err.push_back(Message("unreadVariable", Message::STYLE, "Variable '%1' is assigned a value that is never used", "varname"));
err.push_back(Message("unassignedVariable", Message::STYLE, "Variable '%1' is not assigned a value", "varname"));
err.push_back(Message("constStatement", Message::STYLE, "Redundant code: Found a statement that begins with %1 constant", "type"));
// Generate code..
std::cout << "Generate code.." << std::endl;