From de8ce941722c9f2061fe17ec2d7ee771f99287d6 Mon Sep 17 00:00:00 2001 From: Moltiz <17556456+Moltiz@users.noreply.github.com> Date: Tue, 8 Sep 2026 23:14:12 +0200 Subject: [PATCH] Fix function pointer typedef simplification (#5935) --- lib/tokenize.cpp | 5 ++++- test/testsimplifytypedef.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 49a29f83848..fba08f7d729 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -861,7 +861,10 @@ namespace { } if (isFunctionPointer) { - if (Token::Match(after, "( * %name% ) (")) + // Keep the argument list for a parenthesized pointer declarator: fp *(name). + if (after->previous() != tok3 && Token::Match(after->previous(), "* ( %name% ) ;|,|=")) + after = after->link()->next(); + else if (Token::Match(after, "( * %name% ) (")) after = after->link()->linkAt(1)->next(); else if (after->str() == "(") { useAfterVarRange = false; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 957a1d9e831..8ea0766c977 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -65,6 +65,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(cfp5); TEST_CASE(cfp6); TEST_CASE(cfp7); + TEST_CASE(cfp8); TEST_CASE(carray1); TEST_CASE(carray2); TEST_CASE(carray3); @@ -522,6 +523,16 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS("uint32_t g ( ) ; uint32_t ( * f ) ( uint32_t n ) ;", simplifyTypedef(code)); } + void cfp8() { // #5935 + const char code[] = "typedef TypeDefStruct *(*ThisIsTheProblem)(Type *Var);\n" + "typedef struct Struct1 {\n" + " ThisIsTheProblem *(AnotherType);\n" + "} Struct1;\n"; + const char expected[] = "struct Struct1 { TypeDefStruct * ( * * ( AnotherType ) ) ( Type * Var ) ; } ;"; + ASSERT_EQUALS(expected, simplifyTypedefC(code)); + ASSERT_EQUALS(expected, simplifyTypedef(code)); + } + void carray1() { const char code[] = "typedef int t[20];\n" "t x;\n";