From ce7bfba4164ea1af260b82a10ff5125d59e82082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Sep 2016 16:06:54 +0200 Subject: [PATCH] Refactoring CheckClass::checkConst. Use continue. --- lib/checkclass.cpp | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 719f10ea0..3a082500c 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1692,9 +1692,11 @@ void CheckClass::checkConst() for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { // 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; - // get last token of return type const Token *previous = func->tokenDef->previous(); @@ -1728,36 +1730,36 @@ void CheckClass::checkConst() } // check if base class function is virtual - if (!scope->definedType->derivedFrom.empty()) { - if (func->isImplicitlyVirtual(true)) - continue; - } + 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)) { - std::string classname = scope->className; - const Scope *nest = scope->nestedIn; - while (nest && nest->type != Scope::eGlobal) { - classname = std::string(nest->className + "::" + classname); - nest = nest->nestedIn; - } + if (!checkConstFunc(scope, &*func, memberAccessed)) + continue; - // get function name - std::string functionName = (func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str(); + if (func->isConst() && (memberAccessed || func->isOperator())) + continue; - if (func->tokenDef->str() == "(") - functionName += ")"; - else if (func->tokenDef->str() == "[") - functionName += "]"; - - if (!func->isConst() || (!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()); - } + std::string classname = scope->className; + const Scope *nest = scope->nestedIn; + while (nest && nest->type != Scope::eGlobal) { + classname = std::string(nest->className + "::" + classname); + nest = nest->nestedIn; } + + // get function name + std::string functionName = (func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str(); + + if (func->tokenDef->str() == "(") + functionName += ")"; + else if (func->tokenDef->str() == "[") + functionName += "]"; + + if (func->isInline()) + checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator()); + else // not inline + checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator()); } } }