diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 085a510bb..e84263c36 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -739,30 +739,22 @@ bool isUniqueExpression(const Token* tok) // Iterate over the variables in scope and the parameters of the function if possible const Function * fun = scope->function; const std::list* setOfVars[] = {&scope->varlist, fun ? &fun->argumentList : nullptr}; - if (varType) { - for (const std::list* vars:setOfVars) { - if (!vars) - continue; - for (const Variable& v:*vars) { - if (v.type() && v.type()->name() == varType->name() && v.name() != var->name()) { - return false; - } - } - } - } else { - for (const std::list* vars:setOfVars) { - if (!vars) - continue; - for (const Variable& v:*vars) { - if (v.isFloatingType() == var->isFloatingType() && - v.isEnumType() == var->isEnumType() && - v.isClass() == var->isClass() && - v.isArray() == var->isArray() && - v.isPointer() == var->isPointer() && - v.name() != var->name()) - return false; - } - } + + for (const std::list* vars:setOfVars) { + if (!vars) + continue; + bool other = std::any_of(vars->cbegin(), vars->cend(), [=](const Variable &v) { + if (varType) + return v.type() && v.type()->name() == varType->name() && v.name() != var->name(); + return v.isFloatingType() == var->isFloatingType() && + v.isEnumType() == var->isEnumType() && + v.isClass() == var->isClass() && + v.isArray() == var->isArray() && + v.isPointer() == var->isPointer() && + v.name() != var->name(); + }); + if (other) + return false; } } else if (!isUniqueExpression(tok->astOperand1())) { return false;