Skip to content

Commit ab00a3a

Browse files
Fix #14387 internalError: bad typedef simplification with const-qualified function pointer (danmar#8112)
1 parent eb025fe commit ab00a3a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/tokenize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ namespace {
798798
Token *after = tok3;
799799
while (Token::Match(after, "%name%|*|&|&&|::"))
800800
after = after->next();
801-
if (Token::Match(mNameToken, "%name% (") && Token::simpleMatch(tok3->next(), "*")) {
801+
if (Token::Match(mNameToken, "%name% (") && Token::Match(tok3->next(), "*|const")) {
802802
while (Token::Match(after, "(|["))
803803
after = after->link()->next();
804804
if (after) {
@@ -841,6 +841,8 @@ namespace {
841841
useAfterVarRange = false;
842842
if (Token::simpleMatch(tok3->previous(), "( *"))
843843
tok3->deletePrevious();
844+
else if (Token::simpleMatch(tok3->tokAt(-2), "( * const"))
845+
tok3->tokAt(-1)->deletePrevious();
844846
}
845847
else if (after->str() == "[") {
846848
while (after && after->str() == "[")

test/testsimplifytypedef.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class TestSimplifyTypedef : public TestFixture {
229229
TEST_CASE(simplifyTypedef156);
230230
TEST_CASE(simplifyTypedef157);
231231
TEST_CASE(simplifyTypedef158);
232+
TEST_CASE(simplifyTypedef159);
232233

233234
TEST_CASE(simplifyTypedefFunction1);
234235
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -3803,6 +3804,13 @@ class TestSimplifyTypedef : public TestFixture {
38033804
TODO_ASSERT_EQUALS(exp, cur, tok(code));
38043805
}
38053806

3807+
void simplifyTypedef159() {
3808+
const char code[] = "typedef void (*const func_t)();\n" // #14387
3809+
"func_t g() { return nullptr; }\n";
3810+
const char exp[] = "void * const g ( ) { return nullptr ; }";
3811+
ASSERT_EQUALS(exp, tok(code));
3812+
}
3813+
38063814
void simplifyTypedefFunction1() {
38073815
{
38083816
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)