Skip to content

Commit

Permalink
Fix #11827 FP duplInheritedMember - different return type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 10, 2023
1 parent 9ad18f5 commit 8a14ac3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4396,8 +4396,7 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType
// check for matching return parameters
while (!Token::Match(temp1, "virtual|public:|private:|protected:|{|}|;")) {
if (temp1->str() != temp2->str() &&
!(temp1->str() == derivedFromType->name() &&
temp2->str() == baseType->name())) {
!(temp1->type() && temp2->type() && temp2->type()->isDerivedFrom(temp1->type()->name()))) {
match = false;
break;
}
Expand Down
23 changes: 23 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ class TestClass : public TestFixture {
" T() : S::T() {}\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkDuplInheritedMembers("struct S {};\n" // #11827
"struct SPtr {\n"
" virtual S* operator->() const { return p; }\n"
" S* p = nullptr;\n"
"};\n"
"struct T : public S {};\n"
"struct TPtr : public SPtr {\n"
" T* operator->() const { return (T*)p; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}

#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
Expand Down Expand Up @@ -8349,6 +8360,18 @@ class TestClass : public TestFixture {
" friend T f();\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct S {};\n" // #11827
"struct SPtr {\n"
" virtual S* operator->() const { return p; }\n"
" S* p = nullptr;\n"
"};\n"
"struct T : public S {};\n"
"struct TPtr : public SPtr {\n"
" T* operator->() const { return (T*)p; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'operator.' overrides a function in a base class but is not marked with a 'override' specifier.\n",
errout.str());
}

void overrideCVRefQualifiers() {
Expand Down

0 comments on commit 8a14ac3

Please sign in to comment.