From 0338e99f84bceaab75cf9dd321d3e85a2935b0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 3 Feb 2021 19:25:28 +0100 Subject: [PATCH] CheckClass: Refactoring --- lib/checkclass.cpp | 12 +++++------- test/testclass.cpp | 4 ++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c324c7552..915d0c063 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -534,18 +534,17 @@ bool CheckClass::canNotMove(const Scope *scope) return constructor && !(publicAssign || publicCopy || publicMove); } -static void getAllVariableMembers(const Scope *scope, std::vector& varList, std::vector &baseClasses) +static void getAllVariableMembers(const Scope *scope, std::vector& varList) { - if (std::find(baseClasses.begin(), baseClasses.end(), scope) != baseClasses.end()) - return; - baseClasses.push_back(scope); for (const Variable& var: scope->varlist) varList.push_back(&var); if (scope->definedType) { for (const Type::BaseInfo& baseInfo: scope->definedType->derivedFrom) { + if (scope->definedType == baseInfo.type) + continue; const Scope *baseClass = baseInfo.type ? baseInfo.type->classScope : nullptr; if (baseClass && baseClass->isClassOrStruct() && baseClass->numConstructors == 0) - getAllVariableMembers(baseClass, varList, baseClasses); + getAllVariableMembers(baseClass, varList); } } } @@ -554,8 +553,7 @@ std::vector CheckClass::createUsageList(const Scope *scope) { std::vector ret; std::vector varlist; - std::vector temp; - getAllVariableMembers(scope, varlist, temp); + getAllVariableMembers(scope, varlist); for (const Variable *var: varlist) ret.emplace_back(var); return ret; diff --git a/test/testclass.cpp b/test/testclass.cpp index 66c1c2836..e28d3a5ce 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -571,6 +571,10 @@ private: "};"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'.\n", errout.str()); + // don't crash on recursive template + checkDuplInheritedMembers("template\n" + "struct BitInt : public BitInt { };"); + ASSERT_EQUALS("", errout.str()); } void checkCopyConstructor(const char code[]) {