Fix #11803 FP uselessOverride - overloaded virtual member function (#5211)

This commit is contained in:
chrchr-github 2023-06-30 15:21:08 +02:00 committed by GitHub
parent e9feeef81d
commit 6d9fa6f10a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -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__)