Refactoring; use range for loop

This commit is contained in:
Daniel Marjamäki 2018-07-13 23:32:49 +02:00
parent b2403c36cd
commit ed76f06ca7
1 changed files with 15 additions and 16 deletions

View File

@ -407,9 +407,8 @@ void CheckClass::copyconstructors()
break; break;
} }
if (copyCtor && !copiedVars.empty()) { if (copyCtor && !copiedVars.empty()) {
for (std::set<const Token*>::const_iterator it = copiedVars.begin(); it != copiedVars.end(); ++it) { for (const Token *cv : copiedVars)
copyConstructorShallowCopyError(*it, (*it)->str()); copyConstructorShallowCopyError(cv, cv->str());
}
// throw error if count mismatch // throw error if count mismatch
/* FIXME: This doesn't work. See #4154 /* FIXME: This doesn't work. See #4154
for (std::map<unsigned int, const Token*>::const_iterator i = allocatedVars.begin(); i != allocatedVars.end(); ++i) { for (std::map<unsigned int, const Token*>::const_iterator i = allocatedVars.begin(); i != allocatedVars.end(); ++i) {
@ -477,15 +476,15 @@ bool CheckClass::canNotCopy(const Scope *scope)
bool publicAssign = false; bool publicAssign = false;
bool publicCopy = false; bool publicCopy = false;
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (const Function &func : scope->functionList) {
if (func->isConstructor()) if (func.isConstructor())
constructor = true; constructor = true;
if (func->access != Public) if (func.access != Public)
continue; continue;
if (func->type == Function::eCopyConstructor) { if (func.type == Function::eCopyConstructor) {
publicCopy = true; publicCopy = true;
break; break;
} else if (func->type == Function::eOperatorEqual) { } else if (func.type == Function::eOperatorEqual) {
publicAssign = true; publicAssign = true;
break; break;
} }
@ -501,18 +500,18 @@ bool CheckClass::canNotMove(const Scope *scope)
bool publicCopy = false; bool publicCopy = false;
bool publicMove = false; bool publicMove = false;
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (const Function &func : scope->functionList) {
if (func->isConstructor()) if (func.isConstructor())
constructor = true; constructor = true;
if (func->access != Public) if (func.access != Public)
continue; continue;
if (func->type == Function::eCopyConstructor) { if (func.type == Function::eCopyConstructor) {
publicCopy = true; publicCopy = true;
break; break;
} else if (func->type == Function::eMoveConstructor) { } else if (func.type == Function::eMoveConstructor) {
publicMove = true; publicMove = true;
break; break;
} else if (func->type == Function::eOperatorEqual) { } else if (func.type == Function::eOperatorEqual) {
publicAssign = true; publicAssign = true;
break; break;
} }
@ -668,8 +667,8 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
// Calling member variable function? // Calling member variable function?
if (Token::Match(ftok->next(), "%var% . %name% (")) { if (Token::Match(ftok->next(), "%var% . %name% (")) {
for (std::list<Variable>::const_iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { for (const Variable &var : scope->varlist) {
if (var->declarationId() == ftok->next()->varId()) { if (var.declarationId() == ftok->next()->varId()) {
/** @todo false negative: we assume function changes variable state */ /** @todo false negative: we assume function changes variable state */
assignVar(ftok->next()->varId(), scope, usage); assignVar(ftok->next()->varId(), scope, usage);
break; break;