errmsg: Added message for 'incomplete statement'
This commit is contained in:
parent
a5eb8894d4
commit
fdf5b215f9
|
@ -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());
|
||||
|
|
|
@ -339,12 +339,13 @@ 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();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CppCheck::reportErr(const std::string &errmsg)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue