Some fixes for CheckOther::checkIgnoredReturnValue():
- Fixed name of the function - Fixed false positive for code like "class strcmp { strcmp() {} };" - Fixed FP #6233 on checking side (no AST generated for function call)
This commit is contained in:
parent
b7996bd0b0
commit
b5ea677180
|
@ -2744,7 +2744,7 @@ void CheckOther::varFuncNullUBError(const Token *tok)
|
|||
//---------------------------------------------------------------------------
|
||||
// Check for ignored return values.
|
||||
//---------------------------------------------------------------------------
|
||||
void CheckOther::checkReturnIgnoredReturnValue()
|
||||
void CheckOther::checkIgnoredReturnValue()
|
||||
{
|
||||
if (!_settings->isEnabled("warning"))
|
||||
return;
|
||||
|
@ -2754,9 +2754,12 @@ void CheckOther::checkReturnIgnoredReturnValue()
|
|||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->varId() || !Token::Match(tok, "%var% (") || tok->strAt(-1) == ".")
|
||||
if (tok->varId() || !Token::Match(tok, "%var% (") || tok->strAt(-1) == "." || tok->next()->astOperand1() != tok)
|
||||
continue;
|
||||
|
||||
if (!tok->scope()->isExecutable())
|
||||
tok = tok->scope()->classEnd;
|
||||
|
||||
if (!tok->next()->astParent() && (!tok->function() || !Token::Match(tok->function()->retDef, "void %var%")) && _settings->library.useretval.find(tok->str()) != _settings->library.useretval.end())
|
||||
ignoredReturnValueError(tok, tok->str());
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
checkOther.checkVarFuncNullUB();
|
||||
checkOther.checkNanInArithmeticExpression();
|
||||
checkOther.checkCommaSeparatedReturn();
|
||||
checkOther.checkReturnIgnoredReturnValue();
|
||||
checkOther.checkIgnoredReturnValue();
|
||||
}
|
||||
|
||||
/** @brief Run checks against the simplified token list */
|
||||
|
@ -231,7 +231,7 @@ public:
|
|||
void checkComparisonFunctionIsAlwaysTrueOrFalse();
|
||||
|
||||
/** @brief %Check for ignored return values. */
|
||||
void checkReturnIgnoredReturnValue();
|
||||
void checkIgnoredReturnValue();
|
||||
|
||||
private:
|
||||
// Error messages..
|
||||
|
|
|
@ -6277,6 +6277,11 @@ private:
|
|||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" class strcmp { strcmp() {} };\n" // strcmp is a constructor definition here
|
||||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" return strcmp(a, b);\n"
|
||||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
|
@ -6303,6 +6308,17 @@ private:
|
|||
" DebugLog::getInstance().log(systemInfo.getSystemInfo());\n"
|
||||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #6233
|
||||
check("int main() {\n"
|
||||
" auto lambda = [](double value) {\n"
|
||||
" double rounded = floor(value + 0.5);\n"
|
||||
" printf(\"Rounded value = %f\\n\", rounded);\n"
|
||||
" };\n"
|
||||
" lambda(13.3);\n"
|
||||
" return 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue