From 5ea9519586e1307cf9fca5e41b892267cc4e8015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 5 Mar 2017 22:23:16 +0100 Subject: [PATCH] UseRetVal: Fix FN for methods --- lib/checkfunctions.cpp | 9 +++++---- test/testfunctions.cpp | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 5c71be024..479c11cd0 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -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()); } } } diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 953042523..95ef04f00 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -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"