diff --git a/src/checkstl.cpp b/src/checkstl.cpp index 4fe4d641e..4fe129947 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -232,7 +232,10 @@ void CheckStl::pushback() break; if (Token::Match(tok, "> :: iterator|const_iterator %var% =|;")) { - const std::string iteratorname(tok->strAt(3)); + const unsigned int iteratorid(tok->tokAt(3)->varId()); + if (iteratorid == 0) + continue; + std::string vectorname; int indent = 0; bool invalidIterator = false; @@ -249,7 +252,7 @@ void CheckStl::pushback() } // Assigning iterator.. - if (Token::Match(tok2, (iteratorname + " = %var% . begin ( )").c_str())) + if (Token::Match(tok2, "%varid% = %var% . begin ( )", iteratorid)) { vectorname = tok2->strAt(2); invalidIterator = false; @@ -262,10 +265,10 @@ void CheckStl::pushback() // Using invalid iterator.. if (invalidIterator) { - if (Token::Match(tok2, ("++|--|*|+|-|(|, " + iteratorname).c_str())) - pushbackError(tok2, iteratorname); - if (Token::Match(tok2, (iteratorname + " ++|--|+|-").c_str())) - pushbackError(tok2, iteratorname); + if (Token::Match(tok2, "++|--|*|+|-|(|, %varid%", iteratorid)) + pushbackError(tok2, tok2->strAt(1)); + if (Token::Match(tok2, "%varid% ++|--|+|-", iteratorid)) + pushbackError(tok2, tok2->str()); } } } diff --git a/test/teststl.cpp b/test/teststl.cpp index 7d9330f85..f8c3a7297 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -61,6 +61,7 @@ private: Tokenizer tokenizer; std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); + tokenizer.setVarId(); // Clear the error buffer.. errout.str(""); @@ -260,7 +261,7 @@ private: " *it = 456;\n" " }\n" "}\n"); - TODO_ASSERT_EQUALS("", errout.str()); // Ticket #262 + ASSERT_EQUALS("", errout.str()); } void pushback3()