From de621eab9973311e0b598343995bed1bbcaf0231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 3 Oct 2018 12:54:59 +0200 Subject: [PATCH] Refactoring; use range for loop --- lib/checkclass.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 064856f2c..9b4b6e272 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1773,19 +1773,19 @@ void CheckClass::checkConst() return; for (const Scope * scope : mSymbolDatabase->classAndStructScopes) { - for (std::list::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()); } } }