CheckClass: Fix endless recursion

This commit is contained in:
Daniel Marjamäki 2021-02-03 19:13:49 +01:00
parent 7658aa86bd
commit 205af353db
2 changed files with 19 additions and 7 deletions

View File

@ -137,8 +137,7 @@ void CheckClass::constructors()
}
std::vector<Usage> usageList;
createUsageList(usageList, scope);
std::vector<Usage> usageList = createUsageList(scope);
for (const Function &func : scope->functionList) {
if (!func.hasBody() || !(func.isConstructor() || func.type == Function::eOperatorEqual))
@ -535,19 +534,33 @@ bool CheckClass::canNotMove(const Scope *scope)
return constructor && !(publicAssign || publicCopy || publicMove);
}
void CheckClass::createUsageList(std::vector<Usage>& usageList, const Scope *scope)
static void getAllVariableMembers(const Scope *scope, std::vector<const Variable *>& varList, std::vector<const Scope *> &baseClasses)
{
if (std::find(baseClasses.begin(), baseClasses.end(), scope) != baseClasses.end())
return;
baseClasses.push_back(scope);
for (const Variable& var: scope->varlist)
usageList.push_back(Usage(&var));
varList.push_back(&var);
if (scope->definedType) {
for (const Type::BaseInfo& baseInfo: scope->definedType->derivedFrom) {
const Scope *baseClass = baseInfo.type ? baseInfo.type->classScope : nullptr;
if (baseClass && baseClass->isClassOrStruct() && baseClass->numConstructors == 0)
createUsageList(usageList, baseClass);
getAllVariableMembers(baseClass, varList, baseClasses);
}
}
}
std::vector<CheckClass::Usage> CheckClass::createUsageList(const Scope *scope)
{
std::vector<Usage> ret;
std::vector<const Variable *> varlist;
std::vector<const Scope *> temp;
getAllVariableMembers(scope, varlist, temp);
for (const Variable *var: varlist)
ret.emplace_back(var);
return ret;
}
void CheckClass::assignVar(std::vector<Usage> &usageList, nonneg int varid)
{
for (Usage& usage: usageList) {

View File

@ -296,10 +296,9 @@ private:
/**
* @brief Create usage list that contains all scope members and also members
* of base classes without constructors.
* @param usageList usageList that will be filled up
* @param scope current class scope
*/
static void createUsageList(std::vector<Usage>& usageList, const Scope *scope);
static std::vector<Usage> createUsageList(const Scope *scope);
/**
* @brief assign a variable in the varlist