diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 60aab4087..90d19a74b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1446,8 +1446,11 @@ void Tokenizer::simplifyTypedef() tok2->insertToken("&"); tok2 = tok2->next(); + bool hasName = false; // skip over name - if (tok2->next() && tok2->next()->str() != ")") { + if (tok2->next() && tok2->next()->str() != ")" && tok2->next()->str() != "," && + tok2->next()->str() != ">") { + hasName = true; if (tok2->next()->str() != "(") tok2 = tok2->next(); @@ -1458,12 +1461,13 @@ void Tokenizer::simplifyTypedef() // check for array if (tok2 && tok2->next() && tok2->next()->str() == "[") tok2 = tok2->next()->link(); - } else { - // syntax error } tok2->insertToken(")"); Token::createMutualLinks(tok2->next(), tok3); + + if (!hasName) + tok2 = tok2->next(); } else if (ptrMember) { if (Token::simpleMatch(tok2, "* (")) { tok2->insertToken("*"); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index f630532d2..c727a138b 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -165,6 +165,7 @@ private: TEST_CASE(simplifyTypedef127); // ticket #8878 TEST_CASE(simplifyTypedef128); // ticket #9053 TEST_CASE(simplifyTypedef129); + TEST_CASE(simplifyTypedef130); // ticket #9446 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2602,6 +2603,19 @@ private: } } + void simplifyTypedef130() { // #9446 + const char code[] = "template void a() {\n" + " typedef int(*b)[10];\n" + " a();\n" + "}"; + + const char exp [] = "template < class , class > void a ( ) { " + "a < int ( * ) [ 10 ] , int ( * ) [ 10 ] > ( ) ; " + "}"; + + ASSERT_EQUALS(exp, tok(code, false)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"