diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 733f000a8..a8db352e9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 4f207f111..dfd396959 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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);