From 8ab1ca9ffb2fa544eb7e902d8568b0b1528edc22 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:09:26 +0200 Subject: [PATCH 1/5] Update checkclass.cpp --- lib/checkclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 314af14e158..953bdbcbaa7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1428,7 +1428,7 @@ void CheckClassImpl::privateFunctions() void CheckClassImpl::unusedPrivateFunctionError(const Token* tok1, const Token *tok2, const std::string &classname, const std::string &funcname) { std::list toks{ tok1 }; - if (tok2) + if (tok2 && tok2 != tok1) toks.push_front(tok2); reportError(toks, Severity::style, "unusedPrivateFunction", "$symbol:" + classname + "::" + funcname + "\nUnused private function: '$symbol'", CWE398, Certainty::normal); } From 68a91702615950e1b9d0da6000f6891816e32645 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:11:50 +0200 Subject: [PATCH 2/5] Update testunusedprivfunc.cpp --- test/testunusedprivfunc.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 From a1a673e0880b31dc973e77ec159fcbdad3814fa1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:41:02 +0200 Subject: [PATCH 3/5] Update checkclass.cpp [skip ci] --- lib/checkclass.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 953bdbcbaa7..0c62b95ec67 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* tokDecl, const Token *tokDef, const std::string &classname, const std::string &funcname) { - std::list toks{ tok1 }; - if (tok2 && tok2 != tok1) - toks.push_front(tok2); + std::list toks{ tokDecl }; + if (tokDef && tokDef != tokDecl) + toks.push_front(tokDef); reportError(toks, Severity::style, "unusedPrivateFunction", "$symbol:" + classname + "::" + funcname + "\nUnused private function: '$symbol'", CWE398, Certainty::normal); } From 07d73eb3431eb8ab0977d2d9e19b8c3fb25748c4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:42:51 +0200 Subject: [PATCH 4/5] Update checkclass.h --- lib/checkclass.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkclass.h b/lib/checkclass.h index 2573d99f2f5..94482b0d180 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 *tokDecl, 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); From 1ecac9c7b5c8984043922bdaf5906c04dd9e6b3e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 2 Oct 2026 20:29:04 +0200 Subject: [PATCH 5/5] Rename --- lib/checkclass.cpp | 8 ++++---- lib/checkclass.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 0c62b95ec67..0f02016bd01 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1425,11 +1425,11 @@ void CheckClassImpl::privateFunctions() } } -void CheckClassImpl::unusedPrivateFunctionError(const Token* tokDecl, const Token *tokDef, 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{ tokDecl }; - if (tokDef && tokDef != tokDecl) - toks.push_front(tokDef); + 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 94482b0d180..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 *tokDecl, const Token *tokDef, 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);