Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() == "[")
Expand Down
8 changes: 8 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading