diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 40dbdf88f9d..c472522a6f2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1042,6 +1042,9 @@ void Tokenizer::simplifyTypedef() std::map> numberOfTypedefs; for (Token* tok = list.front(); tok; tok = tok->next()) { if (tok->str() == "typedef") { + if (Token::simpleMatch(tok, "typedef ( *") && Token::simpleMatch(tok->linkAt(1), ") (")) + // Implicit return type + tok->insertToken("int"); TypedefSimplifier ts(tok); if (ts.fail() || !ts.nameToken()) continue; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 03ac9b45a9e..22cad3948d9 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -243,6 +243,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedefFunction9); TEST_CASE(simplifyTypedefFunction10); // #5191 TEST_CASE(simplifyTypedefFunction11); + TEST_CASE(simplifyTypedefFunction12); TEST_CASE(simplifyTypedefStruct); // #12081 - volatile struct @@ -261,6 +262,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(typedefInfo2); TEST_CASE(typedefInfo3); TEST_CASE(typedefInfo4); + TEST_CASE(typedefInfo5); } class TokenizerTest final : public Tokenizer @@ -4444,6 +4446,15 @@ class TestSimplifyTypedef : public TestFixture { ignore_errout(); // we are not interested in the output } + void simplifyTypedefFunction12() { + const char code[] = "typedef (*pfi)(void);\n" + "pfi f;\n"; + + const char expected[] = "int ( * f ) ( void ) ;"; + ASSERT_EQUALS(expected, tok(code, dinit(TokOptions, $.debugwarnings = false))); + ASSERT_EQUALS("", errout_str()); + } + void simplifyTypedefStruct() { const char code1[] = "typedef struct S { int x; } xyz;\n" "xyz var;"; @@ -4673,6 +4684,23 @@ class TestSimplifyTypedef : public TestFixture { " \n" " \n", xml); } + + void typedefInfo5() { + const std::string xml = dumpTypedefInfo("typedef (*pfi)(void);\n"); + ASSERT_EQUALS(" \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n", xml); + } }; REGISTER_TEST(TestSimplifyTypedef)