Skip to content

Commit 9c49edc

Browse files
committed
fix
1 parent c10a3ee commit 9c49edc

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎lib/tokenize.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,18 @@ const Token *Tokenizer::processFunc(const Token *tok2, bool inOperator) const
467467
while (Token::Match(tok2, "%name% ::"))
468468
tok2 = tok2->tokAt(2);
469469

470-
if (Token::simpleMatch(tok2, "const"))
470+
if (Token::simpleMatch(tok2, "const") && !Token::Match(tok2->next(), "[,)]"))
471471
tok2 = tok2->next();
472472

473473
if (!tok2)
474474
return nullptr;
475475

476+
// unnamed array parameter: void f(FN * const [])
477+
while (Token::simpleMatch(tok2, "[") && Token::simpleMatch(tok2->link(), "] ["))
478+
tok2 = tok2->link()->next();
479+
if (Token::simpleMatch(tok2, "["))
480+
tok2 = tok2->link();
481+
476482
if (tok2->str() == "(" &&
477483
tok2->link()->next() &&
478484
tok2->link()->strAt(1) == "(") {

‎test/testsimplifytypedef.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class TestSimplifyTypedef : public TestFixture {
248248
TEST_CASE(simplifyTypedefFunction9);
249249
TEST_CASE(simplifyTypedefFunction10); // #5191
250250
TEST_CASE(simplifyTypedefFunction11);
251+
TEST_CASE(simplifyTypedefFunction12);
251252

252253
TEST_CASE(simplifyTypedefStruct); // #12081 - volatile struct
253254

@@ -4512,6 +4513,20 @@ class TestSimplifyTypedef : public TestFixture {
45124513
ignore_errout(); // we are not interested in the output
45134514
}
45144515

4516+
void simplifyTypedefFunction12() { // #15311
4517+
const char code1[] = "typedef int (FN)(void*);\n"
4518+
"void f(FN * const []);\n";
4519+
ASSERT_EQUALS("void f ( int ( * const [ ] ) ( void * ) ) ;", simplifyTypedefC(code1));
4520+
4521+
const char code2[] = "typedef int (FN)(void*);\n"
4522+
"void f(FN * [2][3]);\n";
4523+
ASSERT_EQUALS("void f ( int ( * [ 2 ] [ 3 ] ) ( void * ) ) ;", simplifyTypedefC(code2));
4524+
4525+
const char code3[] = "typedef int (FN)(void*);\n"
4526+
"void f(FN * const, int);\n";
4527+
ASSERT_EQUALS("void f ( int ( * const ) ( void * ) , int ) ;", simplifyTypedefC(code3));
4528+
}
4529+
45154530
void simplifyTypedefStruct() {
45164531
const char code1[] = "typedef struct S { int x; } xyz;\n"
45174532
"xyz var;\n";

0 commit comments

Comments
 (0)