From 81aed3fbd702c439827e5b05ded873de64d05ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 10 Oct 2010 19:27:42 +0200 Subject: [PATCH] Tokenize: Fixed bug in Tokenize::simplifyKnownVariables --- lib/tokenize.cpp | 13 ------------- test/teststl.cpp | 13 ------------- test/testtokenize.cpp | 16 ++++++++++++++++ 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 172fb46d6..e00212958 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5855,19 +5855,6 @@ bool Tokenizer::simplifyKnownVariables() } } } - - if (tok3->next()->varId() == varid) - { - tok3->next()->str(value); - tok3->next()->varId(valueVarId); - ret = true; - } - else if (tok3->tokAt(3)->varId() == varid) - { - tok3->tokAt(3)->str(value); - tok3->tokAt(3)->varId(valueVarId); - ret = true; - } } if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value)) diff --git a/test/teststl.cpp b/test/teststl.cpp index d8d16fdd6..4d9c02238 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -98,7 +98,6 @@ private: TEST_CASE(missingInnerComparison1); TEST_CASE(missingInnerComparison2); // no FP when there is comparison TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing - TEST_CASE(missingInnerComparison4); // no FP when the iterator is incremented in inner for loop } void check(const std::string &code) @@ -1081,18 +1080,6 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } - - void missingInnerComparison4() - { - check("void f(std::list &ints) {\n" - " for (std::list::iterator it1 = ints.begin(); it1 != ints.end(); ++it1) {\n" - " std::list::iterator it2 = it1;\n" - " for (++it2; it2 != ints.end(); ++it2)\n" - " { }\n" - " }\n" - "}\n"); - TODO_ASSERT_EQUALS("", errout.str()); - } }; REGISTER_TEST(TestStl) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1cec9f805..709cd1594 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -118,6 +118,7 @@ private: TEST_CASE(simplifyKnownVariables27); TEST_CASE(simplifyKnownVariables28); TEST_CASE(simplifyKnownVariables29); // ticket #1811 + TEST_CASE(simplifyKnownVariables30); TEST_CASE(varid1); TEST_CASE(varid2); @@ -1785,6 +1786,21 @@ private: } } + void simplifyKnownVariables30() + { + const char code[] = "int foo() {\n" + " iterator it1 = ints.begin();\n" + " iterator it2 = it1;\n" + " for (++it2;it2!=ints.end();++it2);\n" + "}\n"; + const char expected[] = "int foo ( ) {\n" + "iterator it1 ; it1 = ints . begin ( ) ;\n" + "iterator it2 ; it2 = it1 ;\n" + "for ( ++ it2 ; it2 != ints . end ( ) ; ++ it2 ) { ; }\n" + "}"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + } + std::string tokenizeDebugListing(const std::string &code, bool simplify = false) { Tokenizer tokenizer;