diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 820e23de8..3b19c1d9f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -603,10 +603,24 @@ void Tokenizer::simplifyTypedef() { tok2->str(start->str()); Token * nextToken; + std::list links; for (nextToken = start->next(); nextToken != end->next(); nextToken = nextToken->next()) { tok2->insertToken(nextToken->strAt(0)); tok2 = tok2->next(); + + // Check for links and fix them up + if (tok2->str() == "(") + links.push_back(tok2); + if (tok2->str() == ")") + { + Token * link = links.back(); + + tok2->link(link); + link->link(tok2); + + links.pop_back(); + } } } else diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b5c27d1b2..1ada1aab6 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -143,6 +143,7 @@ private: TEST_CASE(simplifyTypedef6) TEST_CASE(simplifyTypedef7); TEST_CASE(simplifyTypedef8); + TEST_CASE(simplifyTypedef9); TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -2340,6 +2341,25 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } + void simplifyTypedef9() + { + // ticket # 1167 + const char code[] = "typedef std::pair Func;" + "typedef std::vector CallQueue;" + "int main() {}"; + + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Clear the error buffer.. + errout.str(""); + + tokenizer.simplifyTokenList(); + + ASSERT_EQUALS("", errout.str()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));