Skip to content

Commit

Permalink
Fix #11803 FP uselessOverride - overloaded virtual member function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jun 30, 2023
1 parent e10cd1c commit be9525d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8429,6 +8429,17 @@ class TestClass : public TestFixture {
" 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__)
Expand Down

0 comments on commit be9525d

Please sign in to comment.