Handle overloads and custom implementations of functions checkReturnIgnoredReturnValue() to avoid false positives
This commit is contained in:
parent
f75aca1921
commit
b7996bd0b0
|
@ -2757,7 +2757,7 @@ void CheckOther::checkReturnIgnoredReturnValue()
|
|||
if (tok->varId() || !Token::Match(tok, "%var% (") || tok->strAt(-1) == ".")
|
||||
continue;
|
||||
|
||||
if (!tok->next()->astParent() && _settings->library.useretval.find(tok->str()) != _settings->library.useretval.end())
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6265,6 +6265,18 @@ private:
|
|||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function strcmp() is not used.\n", errout.str());
|
||||
|
||||
check("bool strcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.
|
||||
"void foo() {\n"
|
||||
" strcmp(a, b);\n"
|
||||
"}", "test.cpp", false, false, false, true, &settings_std);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function strcmp() is not used.\n", errout.str());
|
||||
|
||||
check("void strcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition which returns void!
|
||||
"void foo() {\n"
|
||||
" strcmp(a, b);\n"
|
||||
"}", "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);
|
||||
|
|
Loading…
Reference in New Issue