diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bebe33015..9da472d47 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -683,11 +683,14 @@ void Tokenizer::simplifyTypedef() if (!inCast) { - tok2 = tok2->next(); + if (tok2->next()->str() != ")" && tok2->next()->str() != ",") + { + tok2 = tok2->next(); - // skip over typedef parameter - if (tok2->next()->str() == "(") - tok2 = tok2->next()->link(); + // skip over typedef parameter + if (tok2->next()->str() == "(") + tok2 = tok2->next()->link(); + } } tok2->insertToken(")"); @@ -949,7 +952,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[]) removeExceptionSpecifications(_tokens); // simplify function pointers - simplifyFunctionPointers(); +// simplifyFunctionPointers(); setVarId(); if (!validate()) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 043c93847..6d99997ab 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -160,6 +160,7 @@ private: TEST_CASE(simplifyTypedef22); TEST_CASE(simplifyTypedef23); TEST_CASE(simplifyTypedef24); + TEST_CASE(simplifyTypedef25); TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -2815,6 +2816,40 @@ private: } } + void simplifyTypedef25() + { + { + // ticket #1298 + const char code[] = "typedef void (*fill_names_f) (const char *);\n" + "struct vfs_class {\n" + " void (*fill_names) (struct vfs_class *me, fill_names_f);\n" + "}"; + + const char expected[] = + "; " + "struct vfs_class { " + "void ( * fill_names ) ( struct vfs_class * me , void ( * ) ( const char * ) ) ; " + "}"; + + ASSERT_EQUALS(expected, tok(code, false)); + } + + { + const char code[] = "typedef void (*fill_names_f) (const char *);\n" + "struct vfs_class {\n" + " void (*fill_names) (fill_names_f, struct vfs_class *me);\n" + "}"; + + const char expected[] = + "; " + "struct vfs_class { " + "void ( * fill_names ) ( void ( * ) ( const char * ) , struct vfs_class * me ) ; " + "}"; + + ASSERT_EQUALS(expected, tok(code, false)); + } + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));