Refactoring; use range for loop

This commit is contained in:
Daniel Marjamäki 2018-10-03 12:54:59 +02:00
parent 90a2a46959
commit de621eab99
1 changed files with 17 additions and 17 deletions

View File

@ -1773,19 +1773,19 @@ void CheckClass::checkConst()
return; return;
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) { for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (const Function &func : scope->functionList) {
// does the function have a body? // does the function have a body?
if (func->type != Function::eFunction || !func->hasBody()) if (func.type != Function::eFunction || !func.hasBody())
continue; continue;
// don't warn for friend/static/virtual methods // don't warn for friend/static/virtual methods
if (func->isFriend() || func->isStatic() || func->isVirtual()) if (func.isFriend() || func.isStatic() || func.isVirtual())
continue; continue;
// get last token of return type // get last token of return type
const Token *previous = func->tokenDef->previous(); const Token *previous = func.tokenDef->previous();
// does the function return a pointer or reference? // does the function return a pointer or reference?
if (Token::Match(previous, "*|&")) { if (Token::Match(previous, "*|&")) {
if (func->retDef->str() != "const") if (func.retDef->str() != "const")
continue; continue;
} else if (Token::Match(previous->previous(), "*|& >")) { } else if (Token::Match(previous->previous(), "*|& >")) {
const Token *temp = previous->previous(); const Token *temp = previous->previous();
@ -1801,11 +1801,11 @@ void CheckClass::checkConst()
if (!foundConst) if (!foundConst)
continue; continue;
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator } else if (func.isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
const std::string& opName = func->tokenDef->str(); const std::string& opName = func.tokenDef->str();
if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*'))) if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
continue; continue;
} else if (Token::simpleMatch(func->retDef, "std :: shared_ptr <")) { } else if (Token::simpleMatch(func.retDef, "std :: shared_ptr <")) {
// Don't warn if a std::shared_ptr is returned // Don't warn if a std::shared_ptr is returned
continue; continue;
} else { } else {
@ -1816,15 +1816,15 @@ void CheckClass::checkConst()
} }
// check if base class function is virtual // check if base class function is virtual
if (!scope->definedType->derivedFrom.empty() && func->isImplicitlyVirtual(true)) if (!scope->definedType->derivedFrom.empty() && func.isImplicitlyVirtual(true))
continue; continue;
bool memberAccessed = false; bool memberAccessed = false;
// if nothing non-const was found. write error.. // if nothing non-const was found. write error..
if (!checkConstFunc(scope, &*func, memberAccessed)) if (!checkConstFunc(scope, &func, memberAccessed))
continue; continue;
if (func->isConst() && (memberAccessed || func->isOperator())) if (func.isConst() && (memberAccessed || func.isOperator()))
continue; continue;
std::string classname = scope->className; std::string classname = scope->className;
@ -1835,17 +1835,17 @@ void CheckClass::checkConst()
} }
// get function name // get function name
std::string functionName = (func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str(); std::string functionName = (func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str();
if (func->tokenDef->str() == "(") if (func.tokenDef->str() == "(")
functionName += ")"; functionName += ")";
else if (func->tokenDef->str() == "[") else if (func.tokenDef->str() == "[")
functionName += "]"; functionName += "]";
if (func->isInline()) if (func.isInline())
checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator()); checkConstError(func.token, classname, functionName, !memberAccessed && !func.isOperator());
else // not inline else // not inline
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator()); checkConstError2(func.token, func.tokenDef, classname, functionName, !memberAccessed && !func.isOperator());
} }
} }
} }