diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6f9cf90a852..6305e0f021a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2295,6 +2295,13 @@ void Tokenizer::simplifyTypedefCpp() tok2 = tok2->tokAt(2); else tok2 = tok2->tokAt(3); + while (tok2->link()) { + tok2 = tok2->link()->next(); + if (Token::simpleMatch(tok2, ";")) { + tok2 = tok2->previous(); + break; + } + } if (!tok2) syntaxError(nullptr); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 342cda59dc8..022412139f1 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -231,6 +231,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedef158); TEST_CASE(simplifyTypedef159); TEST_CASE(simplifyTypedef160); + TEST_CASE(simplifyTypedef161); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3842,6 +3843,22 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS(exp2, simplifyTypedefC(code2)); } + void simplifyTypedef161() { + const char code[] = "namespace N {\n" // #11775 + " typedef int A[3];\n" + " p = new A*[n];\n" + "}\n"; + const char cur[] = "namespace N { p = new int ( * [ n ] ) [ 3 ] ; }"; + const char exp[] = "namespace N { p = new ( int ( * [ n ] ) [ 3 ] ) ; }"; + TODO_ASSERT_EQUALS(exp, cur, tok(code)); + + const char code2[] = "typedef int A[3];\n" + "p = new A*[n];\n"; + const char cur2[] = "p = new int ( * ) [ n ] [ 3 ] ;"; + const char exp2[] = "p = new ( int ( * [ n ] ) [ 3 ] ) ;"; + TODO_ASSERT_EQUALS(exp2, cur2, tok(code2)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"