diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5cf71644b..664b4ad3e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1501,13 +1501,11 @@ void Tokenizer::simplifyTypedef() } } else if (typeOf) { tok2 = TokenList::copyTokens(tok2, argStart, argEnd); - } else if (tok2->strAt(2) == "[") { - do { - if (!tok2->linkAt(2)) - syntaxError(tok2); - - tok2 = tok2->linkAt(2)->previous(); - } while (tok2->strAt(2) == "["); + } else if (Token::Match(tok2, "%name% [")) { + while (Token::Match(tok2, "%name%|] [")) { + tok2 = tok2->linkAt(1); + } + tok2 = tok2->previous(); } if (arrayStart && arrayEnd) { diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 755778cdd..c45f8ab37 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -162,6 +162,7 @@ private: TEST_CASE(simplifyTypedef122); // segmentation fault TEST_CASE(simplifyTypedef123); // ticket #7406 TEST_CASE(simplifyTypedef124); // ticket #7792 + TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[1]; TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2526,6 +2527,13 @@ private: } + void simplifyTypedef125() { // #8749 + const char code[] = "typedef char A[3];\n" + "char (*p)[3] = new A[4];"; + const char exp [] = "char ( * p ) [ 3 ] = new char [ 4 ] [ 3 ] ;"; + ASSERT_EQUALS(exp, tok(code, false)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"