Skip to content

Commit beea1a2

Browse files
Fix #11689 FP constStatement with nested typedefs (#5090)
* Fix #11689 FP constStatement with nested typedefs * Add test
1 parent 107eea2 commit beea1a2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ namespace {
858858
// Function return type => replace array with "*"
859859
for (const Token* a = mRangeAfterVar.first; Token::simpleMatch(a, "["); a = a->link()->next())
860860
tok3->insertToken("*");
861+
} else if (Token::Match(after->previous(), "%name% ( * %name% ) [")) {
862+
after = after->linkAt(4)->next();
861863
} else {
862864
Token* prev = after->previous();
863865
if (prev->isName() && prev != tok3)

test/testsimplifytypedef.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TestSimplifyTypedef : public TestFixture {
6868
TEST_CASE(cfp7);
6969
TEST_CASE(carray1);
7070
TEST_CASE(carray2);
71+
TEST_CASE(carray3);
7172
TEST_CASE(cdonotreplace1);
7273
TEST_CASE(cppfp1);
7374
TEST_CASE(Generic1);
@@ -458,6 +459,20 @@ class TestSimplifyTypedef : public TestFixture {
458459
ASSERT_EQUALS("double x [ 10 ] [ 4 ] ;", simplifyTypedef(code));
459460
}
460461

462+
void carray3() {
463+
const char* code{};
464+
code = "typedef int a[256];\n" // #11689
465+
"typedef a b[256];\n"
466+
"b* p;\n";
467+
ASSERT_EQUALS("int ( * p ) [ 256 ] [ 256 ] ;", simplifyTypedef(code));
468+
469+
code = "typedef int a[1];\n"
470+
"typedef a b[2];\n"
471+
"typedef b c[3];\n"
472+
"c* p;\n";
473+
ASSERT_EQUALS("int ( * p ) [ 3 ] [ 2 ] [ 1 ] ;", simplifyTypedef(code));
474+
}
475+
461476
void cdonotreplace1() {
462477
const char code[] = "typedef int t;\n"
463478
"int* t;";

0 commit comments

Comments
 (0)