diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f2fa8725f..e2e6a342b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -633,23 +633,23 @@ void Tokenizer::simplifyTypedef() { tok2->str(start->str()); Token * nextToken; - std::list links; + std::stack 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() == ")") + if (tok2->str() == "(" || tok2->str() == "[") + links.push(tok2); + if (tok2->str() == ")" || tok2->str() == "]") { - Token * link = links.back(); + Token * link = links.top(); tok2->link(link); link->link(tok2); - links.pop_back(); + links.pop(); } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index fae987b52..c560333d8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -152,6 +152,7 @@ private: TEST_CASE(simplifyTypedef15); TEST_CASE(simplifyTypedef16); TEST_CASE(simplifyTypedef17); + TEST_CASE(simplifyTypedef18); // typedef vector a; TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -2537,6 +2538,23 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } + void simplifyTypedef18() + { + const char code[] = "typedef vector a;\n" + "a b;\n"; + + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Clear the error buffer.. + errout.str(""); + + tokenizer.simplifyTokenList(); + + ASSERT_EQUALS(true, tokenizer.validate()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));