errmsg: Added 'condition is always true/false'
This commit is contained in:
parent
22583269c1
commit
03cfe18c9b
|
@ -193,6 +193,8 @@ void CheckOther::redundantCondition2()
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
void CheckOther::WarningIf()
|
||||
{
|
||||
if (ErrorMessage::ifNoAction(_settings))
|
||||
{
|
||||
// Search for 'if (condition);'
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
|
@ -220,7 +222,10 @@ void CheckOther::WarningIf()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ErrorMessage::conditionAlwaysTrueFalse(_settings))
|
||||
{
|
||||
// Search for 'a=b; if (a==b)'
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
{
|
||||
|
@ -267,14 +272,14 @@ void CheckOther::WarningIf()
|
|||
break;
|
||||
|
||||
// we found the error. Report.
|
||||
std::ostringstream ostr;
|
||||
ostr << _tokenizer->fileLine(tok->tokAt(4)) << ": The condition is always ";
|
||||
bool b = false;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (strcmp(cond, p[i]) == 0)
|
||||
ostr << (i < 3 ? "True" : "False");
|
||||
b = (i < 3);
|
||||
}
|
||||
_errorLogger->reportErr(ErrorMessage::conditionAlwaysTrueFalse(_tokenizer, tok->tokAt(4), b ? "True" : "False"));
|
||||
}
|
||||
_errorLogger->reportErr(ostr.str());
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -313,7 +313,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
checkClass.operatorEq();
|
||||
|
||||
// if (condition);
|
||||
if (ErrorMessage::ifNoAction(_settings))
|
||||
if (ErrorMessage::ifNoAction(_settings) || ErrorMessage::conditionAlwaysTrueFalse(_settings))
|
||||
checkOther.WarningIf();
|
||||
|
||||
// Unused struct members..
|
||||
|
|
|
@ -318,5 +318,14 @@ public:
|
|||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string conditionAlwaysTrueFalse(const Tokenizer *tokenizer, const Token *Location, const std::string &truefalse)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Condition is always " + truefalse + "";
|
||||
}
|
||||
static bool conditionAlwaysTrueFalse(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -93,6 +93,7 @@ int main()
|
|||
err.push_back(Message("charBitOp", Message::style, "Warning - using char variable in bit operation"));
|
||||
err.push_back(Message("variableScope", Message::never, "The scope of the variable %1 can be limited", "varname"));
|
||||
err.push_back(Message("ifAssignment", Message::style, "Assignment in if-condition"));
|
||||
err.push_back(Message("conditionAlwaysTrueFalse", Message::style, "Condition is always %1", "truefalse"));
|
||||
|
||||
// Generate code..
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue