diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 349ca6c0ad1..c6bf2b1f0bd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -467,12 +467,19 @@ const Token *Tokenizer::processFunc(const Token *tok2, bool inOperator) const while (Token::Match(tok2, "%name% ::")) tok2 = tok2->tokAt(2); - if (Token::simpleMatch(tok2, "const")) + if (Token::simpleMatch(tok2, "const") && !Token::Match(tok2->next(), "[,)]")) tok2 = tok2->next(); if (!tok2) return nullptr; + // unnamed array parameter: void f(FN * const []) + if (Token::simpleMatch(tok2, "[")) { + tok2 = tok2->link(); + while (Token::simpleMatch(tok2->next(), "[")) + tok2 = tok2->linkAt(1); + } + if (tok2->str() == "(" && tok2->link()->next() && tok2->link()->strAt(1) == "(") { diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 8ea0766c977..66df6e69d71 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -248,6 +248,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedefFunction9); TEST_CASE(simplifyTypedefFunction10); // #5191 TEST_CASE(simplifyTypedefFunction11); + TEST_CASE(simplifyTypedefFunction12); TEST_CASE(simplifyTypedefStruct); // #12081 - volatile struct @@ -4512,6 +4513,20 @@ class TestSimplifyTypedef : public TestFixture { ignore_errout(); // we are not interested in the output } + void simplifyTypedefFunction12() { // #15311 + const char code1[] = "typedef int (FN)(void*);\n" + "void f(FN * const []);\n"; + ASSERT_EQUALS("void f ( int ( * const [ ] ) ( void * ) ) ;", simplifyTypedefC(code1)); + + const char code2[] = "typedef int (FN)(void*);\n" + "void f(FN * [2][3]);\n"; + ASSERT_EQUALS("void f ( int ( * [ 2 ] [ 3 ] ) ( void * ) ) ;", simplifyTypedefC(code2)); + + const char code3[] = "typedef int (FN)(void*);\n" + "void f(FN * const, int);\n"; + ASSERT_EQUALS("void f ( int ( * const ) ( void * ) , int ) ;", simplifyTypedefC(code3)); + } + void simplifyTypedefStruct() { const char code1[] = "typedef struct S { int x; } xyz;\n" "xyz var;\n";