diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7cb080e071f..b05a0d2e469 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -798,7 +798,7 @@ namespace { Token *after = tok3; while (Token::Match(after, "%name%|*|&|&&|::")) after = after->next(); - if (Token::Match(mNameToken, "%name% (") && Token::simpleMatch(tok3->next(), "*")) { + if (Token::Match(mNameToken, "%name% (") && Token::Match(tok3->next(), "*|const")) { while (Token::Match(after, "(|[")) after = after->link()->next(); if (after) { @@ -841,6 +841,8 @@ namespace { useAfterVarRange = false; if (Token::simpleMatch(tok3->previous(), "( *")) tok3->deletePrevious(); + else if (Token::simpleMatch(tok3->tokAt(-2), "( * const")) + tok3->tokAt(-1)->deletePrevious(); } else if (after->str() == "[") { while (after && after->str() == "[") diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index a24131dd667..087e3759901 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -229,6 +229,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedef156); TEST_CASE(simplifyTypedef157); TEST_CASE(simplifyTypedef158); + TEST_CASE(simplifyTypedef159); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3803,6 +3804,13 @@ class TestSimplifyTypedef : public TestFixture { TODO_ASSERT_EQUALS(exp, cur, tok(code)); } + void simplifyTypedef159() { + const char code[] = "typedef void (*const func_t)();\n" // #14387 + "func_t g() { return nullptr; }\n"; + const char exp[] = "void * const g ( ) { return nullptr ; }"; + ASSERT_EQUALS(exp, tok(code)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"