UseRetVal: Fix FN for methods
This commit is contained in:
parent
603171201a
commit
5ea9519586
|
@ -160,7 +160,10 @@ void CheckFunctions::checkIgnoredReturnValue()
|
|||
if (Token::Match(tok, "%var% (| {"))
|
||||
tok = tok->linkAt(1);
|
||||
|
||||
if (tok->varId() || !Token::Match(tok, "%name% (") || tok->strAt(-1) == ".")
|
||||
if (tok->varId() || !Token::Match(tok, "%name% ("))
|
||||
continue;
|
||||
|
||||
if (tok->next()->astParent())
|
||||
continue;
|
||||
|
||||
if (!tok->scope()->isExecutable()) {
|
||||
|
@ -171,11 +174,9 @@ void CheckFunctions::checkIgnoredReturnValue()
|
|||
const Token* parent = tok;
|
||||
while (parent->astParent() && parent->astParent()->str() == "::")
|
||||
parent = parent->astParent();
|
||||
if (tok->next()->astOperand1() != parent)
|
||||
continue;
|
||||
|
||||
if (!tok->next()->astParent() && (!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && _settings->library.isUseRetVal(tok))
|
||||
ignoredReturnValueError(tok, tok->str());
|
||||
ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -827,7 +827,13 @@ private:
|
|||
check("void foo() {\n"
|
||||
" foo::mystrcmp(a, b);\n"
|
||||
"}", "test.cpp", &settings2);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function mystrcmp() is not used.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function foo::mystrcmp() is not used.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" foo x;\n"
|
||||
" x.mystrcmp(a, b);\n"
|
||||
"}", "test.cpp", &settings2);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function x.mystrcmp() is not used.\n", errout.str());
|
||||
|
||||
check("bool mystrcmp(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"
|
||||
|
|
Loading…
Reference in New Issue