Fix FPs: uselessOverride (#5208)
This commit is contained in:
parent
a40e5817bf
commit
e9feeef81d
|
@ -3082,15 +3082,18 @@ void CheckClass::checkUselessOverride()
|
||||||
for (const Function& func : classScope->functionList) {
|
for (const Function& func : classScope->functionList) {
|
||||||
if (!func.functionScope)
|
if (!func.functionScope)
|
||||||
continue;
|
continue;
|
||||||
|
if (func.hasFinalSpecifier())
|
||||||
|
continue;
|
||||||
const Function* baseFunc = func.getOverriddenFunction();
|
const Function* baseFunc = func.getOverriddenFunction();
|
||||||
if (!baseFunc || baseFunc->isPure())
|
if (!baseFunc || baseFunc->isPure() || baseFunc->access != func.access)
|
||||||
continue;
|
continue;
|
||||||
if (const Token* const call = getSingleFunctionCall(func.functionScope)) {
|
if (const Token* const call = getSingleFunctionCall(func.functionScope)) {
|
||||||
if (call->function() != baseFunc)
|
if (call->function() != baseFunc)
|
||||||
continue;
|
continue;
|
||||||
std::vector<const Token*> funcArgs = getArguments(func.tokenDef);
|
std::vector<const Token*> funcArgs = getArguments(func.tokenDef);
|
||||||
std::vector<const Token*> callArgs = getArguments(call);
|
std::vector<const Token*> callArgs = getArguments(call);
|
||||||
if (!std::equal(funcArgs.begin(), funcArgs.end(), callArgs.begin(), [](const Token* t1, const Token* t2) {
|
if (funcArgs.size() != callArgs.size() ||
|
||||||
|
!std::equal(funcArgs.begin(), funcArgs.end(), callArgs.begin(), [](const Token* t1, const Token* t2) {
|
||||||
return t1->str() == t2->str();
|
return t1->str() == t2->str();
|
||||||
}))
|
}))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -8403,6 +8403,32 @@ private:
|
||||||
" int f() override { return B::f(); }\n"
|
" int f() override { return B::f(); }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUselessOverride("struct S { virtual void f(); };\n"
|
||||||
|
"struct D : S {\n"
|
||||||
|
" void f() final { S::f(); }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUselessOverride("struct S {\n"
|
||||||
|
"protected:\n"
|
||||||
|
" virtual void f();\n"
|
||||||
|
"};\n"
|
||||||
|
"struct D : S {\n"
|
||||||
|
"public:\n"
|
||||||
|
" void f() override { S::f(); }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUselessOverride("struct B { virtual void f(int, int, int) const; };\n" // #11799
|
||||||
|
"struct D : B {\n"
|
||||||
|
" int m = 42;\n"
|
||||||
|
" void f(int a, int b, int c) const override;\n"
|
||||||
|
"};\n"
|
||||||
|
"void D::f(int a, int b, int c) const {\n"
|
||||||
|
" B::f(a, b, m);\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)
|
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)
|
||||||
|
|
Loading…
Reference in New Issue