diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 915d0c063..616a4207e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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) { diff --git a/test/testclass.cpp b/test/testclass.cpp index e28d3a5ce..75d1d8207 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -575,6 +575,21 @@ private: checkDuplInheritedMembers("template\n" "struct BitInt : public BitInt { };"); ASSERT_EQUALS("", errout.str()); + + // don't crash on recursive template + checkDuplInheritedMembers("namespace _impl {\n" + " template \n" + " struct fn_traits;\n" + "}\n" + "template \n" + "struct function_traits\n" + " : public _impl::fn_traits> {};\n" + "namespace _impl {\n" + " template \n" + " struct fn_traits\n" + " : public fn_traits {};\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkCopyConstructor(const char code[]) {