Skip to content

Commit

Permalink
Fix #12311 FP duplInheritedMember for const overload (#5829)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 4, 2024
1 parent 73187e6 commit f24c7fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,8 @@ static std::vector<DuplMemberFuncInfo> getDuplInheritedMemberFunctionsRecursive(
if (classFuncIt.name() == parentClassFuncIt.name() &&
(parentClassFuncIt.access != AccessControl::Private || !skipPrivate) &&
!classFuncIt.isConstructor() && !classFuncIt.isDestructor() &&
classFuncIt.argsMatch(parentClassIt.type->classScope, parentClassFuncIt.argDef, classFuncIt.argDef, emptyString, 0))
classFuncIt.argsMatch(parentClassIt.type->classScope, parentClassFuncIt.argDef, classFuncIt.argDef, emptyString, 0) &&
(classFuncIt.isConst() == parentClassFuncIt.isConst() || Function::returnsConst(&classFuncIt) == Function::returnsConst(&parentClassFuncIt)))
results.emplace_back(&classFuncIt, &parentClassFuncIt, &parentClassIt);
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ class TestClass : public TestFixture {
" T* operator->() const { return (T*)p; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkDuplInheritedMembers("struct B { virtual int& get() = 0; };\n" // #12311
"struct D : B {\n"
" int i{};\n"
" int& get() override { return i; }\n"
" const int& get() const { return i; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}

#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
Expand Down

0 comments on commit f24c7fd

Please sign in to comment.