From 384729204f732377ba8a2ead59861cac9778bb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Mar 2011 09:48:53 +0100 Subject: [PATCH] Refactoring: Use SymbolDatabase to determine if variable is a iterator --- lib/checkstl.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index a5de43eb0..fa4e8c29a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -439,8 +439,18 @@ void CheckStl::erase() { if (Token::Match(tok2, "; %var% !=")) { - const unsigned int varid = tok2->next()->varId(); - if (varid > 0 && Token::findmatch(_tokenizer->tokens(), "> :: iterator %varid%", varid)) + // Get declaration token for var.. + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + const Variable *variableInfo = symbolDatabase->getVariableFromVarId(tok2->next()->varId()); + const Token *decltok = variableInfo ? variableInfo->typeEndToken() : NULL; + + // Is variable an iterator? + bool isIterator = false; + if (decltok && Token::Match(decltok->tokAt(-2), "> :: iterator %varid%", tok2->next()->varId())) + isIterator = true; + + // If tok2->next() is an iterator, check scope + if (isIterator) EraseCheckLoop::checkScope(this, tok2->next()); } break;