diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 314af14e158..0f02016bd01 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1425,11 +1425,11 @@ void CheckClassImpl::privateFunctions() } } -void CheckClassImpl::unusedPrivateFunctionError(const Token* tok1, const Token *tok2, const std::string &classname, const std::string &funcname) +void CheckClassImpl::unusedPrivateFunctionError(const Token* tokImpl, const Token *tokDef, const std::string &classname, const std::string &funcname) { - std::list toks{ tok1 }; - if (tok2) - toks.push_front(tok2); + std::list toks{ tokDef }; + if (tokDef != tokImpl) + toks.push_back(tokImpl); reportError(toks, Severity::style, "unusedPrivateFunction", "$symbol:" + classname + "::" + funcname + "\nUnused private function: '$symbol'", CWE398, Certainty::normal); } diff --git a/lib/checkclass.h b/lib/checkclass.h index 2573d99f2f5..0aa8fc29da3 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -186,7 +186,7 @@ class CPPCHECKLIB CheckClassImpl : public CheckImpl { void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname); void missingMemberCopyError(const Token *tok, FunctionType functionType, const std::string& classname, const std::string& varname); void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname, bool inconclusive); - void unusedPrivateFunctionError(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname); + void unusedPrivateFunctionError(const Token *tokImpl, const Token *tokDef, const std::string &classname, const std::string &funcname); void memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type, bool isContainer = false); void memsetErrorReference(const Token *tok, const std::string &memfunc, const std::string &type); void memsetErrorFloat(const Token *tok, const std::string &type); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 621ee11f184..09623db97c5 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -274,7 +274,7 @@ class TestUnusedPrivateFunction : public TestFixture { "Fred::Fred()\n" "{}\n"); - ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:6:12]: (style) Unused private function: 'Fred::get' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (style) Unused private function: 'Fred::get' [unusedPrivateFunction]\n", errout_str()); } @@ -407,7 +407,7 @@ class TestUnusedPrivateFunction : public TestFixture { " C() = default;\n" " void f() const { (void)this; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:3:10]: (style) Unused private function: 'C::f' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style) Unused private function: 'C::f' [unusedPrivateFunction]\n", errout_str()); } @@ -424,7 +424,7 @@ class TestUnusedPrivateFunction : public TestFixture { " static void f()\n" " { }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:10:17] -> [test.cpp:10:17]: (style) Unused private function: 'A::f' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:17]: (style) Unused private function: 'A::f' [unusedPrivateFunction]\n", errout_str()); check("class A\n" "{\n" @@ -460,7 +460,7 @@ class TestUnusedPrivateFunction : public TestFixture { " class I { I() = default; };\n" " void f() const { (void)this; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:3:10]: (style) Unused private function: 'C::f' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style) Unused private function: 'C::f' [unusedPrivateFunction]\n", errout_str()); } @@ -501,7 +501,7 @@ class TestUnusedPrivateFunction : public TestFixture { " void foo() {}\n" // Skip for overrides of virtual functions of base " void bar() {}\n" // Don't skip if no function is overridden "};\n"); - ASSERT_EQUALS("[test.cpp:9:10] -> [test.cpp:9:10]: (style) Unused private function: 'derived::bar' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (style) Unused private function: 'derived::bar' [unusedPrivateFunction]\n", errout_str()); check("class Base {\n" "private:\n" @@ -576,7 +576,7 @@ class TestUnusedPrivateFunction : public TestFixture { " friend Bar;\n" " void f() { }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5:10] -> [test.cpp:5:10]: (style) Unused private function: 'Foo::f' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (style) Unused private function: 'Foo::f' [unusedPrivateFunction]\n", errout_str()); check("struct F;\n" // #10265 "struct S {\n" @@ -663,7 +663,7 @@ class TestUnusedPrivateFunction : public TestFixture { " void startListening() {\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8:10] -> [test.cpp:8:10]: (style) Unused private function: 'Fred::startListening' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:10]: (style) Unused private function: 'Fred::startListening' [unusedPrivateFunction]\n", errout_str()); // #5059 check("class Fred {\n" @@ -813,7 +813,7 @@ class TestUnusedPrivateFunction : public TestFixture { "};\n" "int Foo::i = sth();\n" "int i = F();\n"); - ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:3:16]: (style) Unused private function: 'Foo::F' [unusedPrivateFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Unused private function: 'Foo::F' [unusedPrivateFunction]\n", errout_str()); } void templateSimplification() { //ticket #6183