diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3c6b02275..f14c19d16 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5734,9 +5734,9 @@ void Tokenizer:: simplifyFunctionPointers() else if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|(|public:|protected:|private:")) continue; - if (Token::Match(tok, "%type% *| *| ( * %var% ) (")) + if (Token::Match(tok, "%type% *| *| ( * %var% [| ]| ) (")) ; - else if (Token::Match(tok, "%type% %type% *| *| ( * %var% ) (")) + else if (Token::Match(tok, "%type% %type% *| *| ( * %var% [| ]| ) (")) tok = tok->next(); else continue; @@ -5745,13 +5745,14 @@ void Tokenizer:: simplifyFunctionPointers() tok = tok->next(); // check that the declaration ends - if (!Token::Match(tok->linkAt(5), ") ;|,|)|=|[")) + const Token *endTok = tok->next()->link()->next()->link(); + if (!Token::Match(endTok, ") ;|,|)|=|[")) continue; // ok simplify this function pointer to an ordinary pointer + Token::eraseTokens(tok->next()->link(), endTok->next()); + tok->next()->link()->deleteThis(); tok->deleteNext(); - tok->tokAt(2)->deleteNext(); - Token::eraseTokens(tok->tokAt(2), tok->linkAt(3)->next()); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c89c43f6d..1df184374 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -315,6 +315,7 @@ private: TEST_CASE(functionpointer2); TEST_CASE(functionpointer3); TEST_CASE(functionpointer4); + TEST_CASE(functionpointer5); TEST_CASE(removeRedundantAssignment); @@ -5078,6 +5079,13 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code, false)); } + void functionpointer5() { + const char code[] = ";void (*fp[])(int a) = {0,0,0};"; + const char expected[] = "\n\n##file 0\n" + "1: ; void * fp@1 [ ] = { 0 , 0 , 0 } ;\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, false)); + } + void removeRedundantAssignment() { ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true)); ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));