Refactoring CheckClass::checkConst. Use continue.

This commit is contained in:
Daniel Marjamäki 2016-09-04 16:06:54 +02:00
parent 54db79305b
commit ce7bfba416
1 changed files with 28 additions and 26 deletions

View File

@ -1692,9 +1692,11 @@ void CheckClass::checkConst()
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
// does the function have a body? // does the function have a body?
if (func->type != Function::eFunction || !func->hasBody() || func->isFriend() || func->isStatic() || func->isVirtual()) if (func->type != Function::eFunction || !func->hasBody())
continue;
// don't warn for friend/static/virtual methods
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();
@ -1728,14 +1730,17 @@ void CheckClass::checkConst()
} }
// check if base class function is virtual // check if base class function is virtual
if (!scope->definedType->derivedFrom.empty()) { if (!scope->definedType->derivedFrom.empty() && func->isImplicitlyVirtual(true))
if (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;
if (func->isConst() && (memberAccessed || func->isOperator()))
continue;
std::string classname = scope->className; std::string classname = scope->className;
const Scope *nest = scope->nestedIn; const Scope *nest = scope->nestedIn;
while (nest && nest->type != Scope::eGlobal) { while (nest && nest->type != Scope::eGlobal) {
@ -1751,15 +1756,12 @@ void CheckClass::checkConst()
else if (func->tokenDef->str() == "[") else if (func->tokenDef->str() == "[")
functionName += "]"; functionName += "]";
if (!func->isConst() || (!memberAccessed && !func->isOperator())) {
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());
} }
} }
}
}
} }
bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const