From 6d9fa6f10adfb01f8675ec3edf9c5c380c716fb9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:21:08 +0200 Subject: [PATCH] Fix #11803 FP uselessOverride - overloaded virtual member function (#5211) --- lib/checkclass.cpp | 6 ++++++ test/testclass.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 327830fb7..14ce236d7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3087,6 +3087,12 @@ void CheckClass::checkUselessOverride() const Function* baseFunc = func.getOverriddenFunction(); if (!baseFunc || baseFunc->isPure() || baseFunc->access != func.access) continue; + if (std::any_of(classScope->functionList.begin(), classScope->functionList.end(), [&func](const Function& f) { // check for overloads + if (&f == &func) + return false; + return f.name() == func.name(); + })) + continue; if (const Token* const call = getSingleFunctionCall(func.functionScope)) { if (call->function() != baseFunc) continue; diff --git a/test/testclass.cpp b/test/testclass.cpp index f9a96b41c..85f0c7f0a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8429,6 +8429,17 @@ private: " B::f(a, b, m);\n" "};"); ASSERT_EQUALS("", errout.str()); + + checkUselessOverride("struct B {\n" // #11803 + " virtual void f();\n" + " virtual void f(int i);\n" + "};\n" + "struct D : B {\n" + " void f() override { B::f(); }\n" + " void f(int i) override;\n" + " void g() { f(); }\n" + "};"); + ASSERT_EQUALS("", errout.str()); } #define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)