Fixed #8412 (ignoredReturnValue not issued when return value is changed but not really used (by logical not for example))

This commit is contained in:
Daniel Marjamäki 2021-04-04 18:26:07 +02:00
parent 44f914eaee
commit 518fb01553
2 changed files with 11 additions and 1 deletions

View File

@ -204,7 +204,10 @@ void CheckFunctions::checkIgnoredReturnValue()
if (tok->varId() || !Token::Match(tok, "%name% (") || tok->isKeyword())
continue;
if (tok->next()->astParent())
const Token *parent = tok->next()->astParent();
while (Token::Match(parent, "%cop%"))
parent = parent->astParent();
if (parent)
continue;
if (!tok->scope()->isExecutable()) {

View File

@ -1231,6 +1231,13 @@ private:
"}\n"
"A g() { return f(1); }");
ASSERT_EQUALS("", errout.str());
// #8412 - unused operator result
check("void foo() {\n"
" !mystrcmp(a, b);\n"
"}", "test.cpp", &settings2);
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function mystrcmp() is not used.\n", errout.str());
}
void checkIgnoredErrorCode() {