fix #10169 (CheckClass::checkDuplInheritedMembersRecursive) (#3114)

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
IOBYTE 2021-02-05 05:05:07 -05:00 committed by GitHub
parent be09361279
commit da3eb2e411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -2548,6 +2548,9 @@ void CheckClass::checkDuplInheritedMembersRecursive(const Type* typeCurrent, con
// Check if there is info about the 'Base' class
if (!parentClassIt.type || !parentClassIt.type->classScope)
continue;
// Don't crash on recursive templates
if (parentClassIt.type == typeBase)
continue;
// Check if they have a member variable in common
for (const Variable &classVarIt : typeCurrent->classScope->varlist) {
for (const Variable &parentClassVarIt : parentClassIt.type->classScope->varlist) {

View File

@ -575,6 +575,21 @@ private:
checkDuplInheritedMembers("template<size_t N>\n"
"struct BitInt : public BitInt<N+1> { };");
ASSERT_EQUALS("", errout.str());
// don't crash on recursive template
checkDuplInheritedMembers("namespace _impl {\n"
" template <typename AlwaysVoid, typename>\n"
" struct fn_traits;\n"
"}\n"
"template <typename T>\n"
"struct function_traits\n"
" : public _impl::fn_traits<void, std::remove_reference_t<T>> {};\n"
"namespace _impl {\n"
" template <typename T>\n"
" struct fn_traits<decltype(void(&T::operator())), T>\n"
" : public fn_traits<void, decltype(&T::operator())> {};\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkCopyConstructor(const char code[]) {