Skip to content

Commit

Permalink
Fix #12597 syntaxError with array typedef in namespace (#6287)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Apr 13, 2024
1 parent fe3bf91 commit 01c049d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,8 @@ void Tokenizer::simplifyTypedefCpp()
tok2 = tok3->tokAt(3);
else if (Token::Match(tok2->tokAt(3), "[(),;]"))
tok2 = tok2->tokAt(2);
else if (Token::simpleMatch(tok2->tokAt(3), ">"))
tok2 = tok2->tokAt(2);
else
tok2 = tok2->tokAt(3);
if (!tok2)
Expand Down
13 changes: 13 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedef148);
TEST_CASE(simplifyTypedef149);
TEST_CASE(simplifyTypedef150);
TEST_CASE(simplifyTypedef151);

TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
Expand Down Expand Up @@ -3530,6 +3531,18 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void simplifyTypedef151() {
const char* code{}, *exp{};
code = "namespace N {\n" // #12597
" typedef int T[10];\n"
" const T* f() { return static_cast<const T*>(nullptr); }\n"
"}\n";
exp = "namespace N { "
"const int ( * f ( ) ) [ 10 ] { return static_cast < const int ( * ) [ 10 ] > ( nullptr ) ; } "
"}";
ASSERT_EQUALS(exp, tok(code));
}

void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"
Expand Down

0 comments on commit 01c049d

Please sign in to comment.