Refactoring; use range for loop
This commit is contained in:
parent
90a2a46959
commit
de621eab99
|
@ -1773,19 +1773,19 @@ void CheckClass::checkConst()
|
|||
return;
|
||||
|
||||
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?
|
||||
if (func->type != Function::eFunction || !func->hasBody())
|
||||
if (func.type != Function::eFunction || !func.hasBody())
|
||||
continue;
|
||||
// don't warn for friend/static/virtual methods
|
||||
if (func->isFriend() || func->isStatic() || func->isVirtual())
|
||||
if (func.isFriend() || func.isStatic() || func.isVirtual())
|
||||
continue;
|
||||
// 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?
|
||||
if (Token::Match(previous, "*|&")) {
|
||||
if (func->retDef->str() != "const")
|
||||
if (func.retDef->str() != "const")
|
||||
continue;
|
||||
} else if (Token::Match(previous->previous(), "*|& >")) {
|
||||
const Token *temp = previous->previous();
|
||||
|
@ -1801,11 +1801,11 @@ void CheckClass::checkConst()
|
|||
|
||||
if (!foundConst)
|
||||
continue;
|
||||
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
|
||||
const std::string& opName = func->tokenDef->str();
|
||||
} else if (func.isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
|
||||
const std::string& opName = func.tokenDef->str();
|
||||
if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
|
||||
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
|
||||
continue;
|
||||
} else {
|
||||
|
@ -1816,15 +1816,15 @@ void CheckClass::checkConst()
|
|||
}
|
||||
|
||||
// check if base class function is virtual
|
||||
if (!scope->definedType->derivedFrom.empty() && func->isImplicitlyVirtual(true))
|
||||
if (!scope->definedType->derivedFrom.empty() && func.isImplicitlyVirtual(true))
|
||||
continue;
|
||||
|
||||
bool memberAccessed = false;
|
||||
// if nothing non-const was found. write error..
|
||||
if (!checkConstFunc(scope, &*func, memberAccessed))
|
||||
if (!checkConstFunc(scope, &func, memberAccessed))
|
||||
continue;
|
||||
|
||||
if (func->isConst() && (memberAccessed || func->isOperator()))
|
||||
if (func.isConst() && (memberAccessed || func.isOperator()))
|
||||
continue;
|
||||
|
||||
std::string classname = scope->className;
|
||||
|
@ -1835,17 +1835,17 @@ void CheckClass::checkConst()
|
|||
}
|
||||
|
||||
// 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 += ")";
|
||||
else if (func->tokenDef->str() == "[")
|
||||
else if (func.tokenDef->str() == "[")
|
||||
functionName += "]";
|
||||
|
||||
if (func->isInline())
|
||||
checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator());
|
||||
if (func.isInline())
|
||||
checkConstError(func.token, classname, functionName, !memberAccessed && !func.isOperator());
|
||||
else // not inline
|
||||
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator());
|
||||
checkConstError2(func.token, func.tokenDef, classname, functionName, !memberAccessed && !func.isOperator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue