diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 96a4858de..e279473e0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1064,11 +1064,14 @@ void Tokenizer::simplifyTypedef() } } - while (!pointers.empty()) + if (!pointers.empty()) { - tok2->insertToken(pointers.front().c_str()); - pointers.pop_front(); - tok2 = tok2->next(); + std::list::const_iterator iter; + for (iter = pointers.begin(); iter != pointers.end(); ++iter) + { + tok2->insertToken(*iter); + tok2 = tok2->next(); + } } if (functionPtr || functionRef || function) @@ -1198,6 +1201,7 @@ void Tokenizer::simplifyTypedef() arrayStart = 0; arrayEnd = 0; offset = 1; + pointers.clear(); while (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "*|&")) pointers.push_back(tok->tokAt(offset++)->str()); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b4385816a..b745c5e6a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -191,6 +191,7 @@ private: TEST_CASE(simplifyTypedef46); // ticket #1615 TEST_CASE(simplifyTypedef47); TEST_CASE(simplifyTypedef48); // ticket #1673 + TEST_CASE(simplifyTypedef49); // ticket #1691 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3989,6 +3990,23 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void simplifyTypedef49() // ticket #1691 + { + const char code[] = "class Class2 {\n" + "typedef const Class & Const_Reference;\n" + "void some_method (Const_Reference x) const {}\n" + "void another_method (Const_Reference x) const {}\n" + "}"; + + // The expected result.. + const std::string expected("class Class2 { " + "; " + "void some_method ( const Class & x ) const { } " + "void another_method ( const Class & x ) const { } " + "}"); + ASSERT_EQUALS(expected, sizeof_(code)); + } + void simplifyTypedefFunction1() { {