diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ccfaa351b..9d728b3d5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1494,8 +1494,9 @@ void Tokenizer::simplifyTypedef() tok2 = tok2->next(); if (openParenthesis) { - // skip over name - tok2 = tok2->next(); + // Skip over name, if any + if (Token::Match(tok2->next(), "%name%")) + tok2 = tok2->next(); tok2->insertToken(")"); tok2 = tok2->next(); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index c27896739..4a0031bd2 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -164,6 +164,7 @@ private: TEST_CASE(simplifyTypedef124); // ticket #7792 TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[1]; TEST_CASE(simplifyTypedef126); // ticket #5953 + TEST_CASE(simplifyTypedef127); // ticket #8878 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2540,6 +2541,16 @@ private: ASSERT_EQUALS(exp, tok(code, false)); } + void simplifyTypedef127() { // #8878 + const char code[] = "class a; typedef int (a::*b); " + "template struct c; " + "template struct d { enum { e = c::f }; };"; + const char exp [] = "class a ; " + "template < long , class > struct c ; " + "template < int g > struct d { enum Anonymous0 { e = c < g , int ( a :: * ) > :: f } ; } ;"; + ASSERT_EQUALS(exp, tok(code, false)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"