Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading