diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 65fa04dd0..f630a4c0a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5563,7 +5563,7 @@ void Tokenizer:: simplifyFunctionPointers() tok = tok->next(); // check that the declaration ends - if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|=")) + if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|=|[")) continue; // ok simplify this function pointer to an ordinary pointer diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b94295294..5406b6bf6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -267,7 +267,8 @@ private: TEST_CASE(simplifyConst); TEST_CASE(switchCase); - TEST_CASE(functionpointer); + TEST_CASE(functionpointer1); + TEST_CASE(functionpointer2); TEST_CASE(removeRedundantAssignment); @@ -4738,7 +4739,7 @@ private: return ostr.str(); } - void functionpointer() + void functionpointer1() { ASSERT_EQUALS(" void* f;", simplifyFunctionPointers("void (*f)();")); ASSERT_EQUALS(" void** f;", simplifyFunctionPointers("void *(*f)();")); @@ -4746,6 +4747,19 @@ private: ASSERT_EQUALS(" unsigned int** f;", simplifyFunctionPointers("unsigned int * (*f)();")); } + void functionpointer2() + { + const char code[] = "typedef void (* PF)();" + "void f1 ( ) { }" + "PF pf = &f1;" + "PF pfs[] = { &f1, &f1 };"; + const char expected[] = "; " + "void f1(){} " + "void* pf; pf=& f1; " + "void* pfs[]={& f1,& f1};"; + ASSERT_EQUALS(expected, simplifyFunctionPointers(code)); + } + void removeRedundantAssignment() { ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));