From e5527370285664b4b735382f6a43d40bc12a1571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 13 Jul 2018 16:46:29 +0200 Subject: [PATCH] Refactoring: Use range for loop --- lib/checkstl.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 80afff4bf..0206e5635 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -345,9 +345,7 @@ void CheckStl::mismatchingContainers() { // Check if different containers are used in various calls of standard functions const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); - const std::size_t functions = symbolDatabase->functionScopes.size(); - for (std::size_t ii = 0; ii < functions; ++ii) { - const Scope * scope = symbolDatabase->functionScopes[ii]; + for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% ( !!)")) continue; @@ -404,15 +402,15 @@ void CheckStl::stlOutOfBounds() const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); // Scan through all scopes.. - for (std::list::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { - const Token* tok = i->classDef; + for (const Scope &scope : symbolDatabase->scopeList) { + const Token* tok = scope.classDef; // only interested in conditions - if ((i->type != Scope::eFor && i->type != Scope::eWhile && i->type != Scope::eIf && i->type != Scope::eDo) || !tok) + if ((scope.type != Scope::eFor && scope.type != Scope::eWhile && scope.type != Scope::eIf && scope.type != Scope::eDo) || !tok) continue; - if (i->type == Scope::eFor) + if (scope.type == Scope::eFor) tok = Token::findsimplematch(tok->tokAt(2), ";"); - else if (i->type == Scope::eDo) { + else if (scope.type == Scope::eDo) { tok = tok->linkAt(1)->tokAt(2); } else tok = tok->next(); @@ -442,7 +440,7 @@ void CheckStl::stlOutOfBounds() // variable id for the container variable const unsigned int declarationId = var->declarationId(); - for (const Token *tok3 = i->bodyStart; tok3 && tok3 != i->bodyEnd; tok3 = tok3->next()) { + for (const Token *tok3 = scope.bodyStart; tok3 && tok3 != scope.bodyEnd; tok3 = tok3->next()) { if (tok3->varId() == declarationId) { tok3 = tok3->next(); if (Token::Match(tok3, ". %name% ( )")) {