From 3ad2e6c87453b71eba02c67f5bd1d4975f2adade Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:57:48 +0200 Subject: [PATCH 1/3] Update testsimplifytypedef.cpp --- test/testsimplifytypedef.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 3118afa31ce..4970e863c5d 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -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 @@ -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(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" From f58bdc01ed6841f2c9fbdd9c76710432ac80ff20 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:58:55 +0200 Subject: [PATCH 2/3] Update tokenize.cpp --- lib/tokenize.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 25317d38de2..223f8f329c6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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) From fe8138edd4ae8e1064557b47e7e544f2e5f70f04 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:26:08 +0200 Subject: [PATCH 3/3] Format --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 223f8f329c6..e8a30461917 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2249,7 +2249,7 @@ 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), ">")) + else if (Token::simpleMatch(tok2->tokAt(3), ">")) tok2 = tok2->tokAt(2); else tok2 = tok2->tokAt(3);