Skip to content

Commit b99931c

Browse files
Fix #11808 FP uselessOverride - grandchildren calling grandfather (#5212)
1 parent 96955cc commit b99931c

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,13 +4388,13 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType
43884388
auto range = parent->functionMap.equal_range(tokenDef->str());
43894389
for (std::multimap<std::string, const Function*>::const_iterator it = range.first; it != range.second; ++it) {
43904390
const Function * func = it->second;
4391-
if (func->hasVirtualSpecifier()) { // Base is virtual and of same name
4391+
if (func->isImplicitlyVirtual()) { // Base is virtual and of same name
43924392
const Token *temp1 = func->tokenDef->previous();
43934393
const Token *temp2 = tokenDef->previous();
43944394
bool match = true;
43954395

43964396
// check for matching return parameters
4397-
while (temp1->str() != "virtual") {
4397+
while (!Token::Match(temp1, "virtual|{|}|;")) {
43984398
if (temp1->str() != temp2->str() &&
43994399
!(temp1->str() == derivedFromType->name() &&
44004400
temp2->str() == baseType->name())) {

test/testclass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8440,6 +8440,15 @@ class TestClass : public TestFixture {
84408440
" void g() { f(); }\n"
84418441
"};");
84428442
ASSERT_EQUALS("", errout.str());
8443+
8444+
checkUselessOverride("struct B { virtual void f(); };\n" // #11808
8445+
"struct D : B { void f() override {} };\n"
8446+
"struct D2 : D {\n"
8447+
" void f() override {\n"
8448+
" B::f();\n"
8449+
" }\n"
8450+
"};");
8451+
ASSERT_EQUALS("", errout.str());
84438452
}
84448453

84458454
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)

0 commit comments

Comments
 (0)