From 3900ac731e98efd3183f3e53a89b9a51c0b18dce Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 29 Dec 2010 20:25:47 +0100 Subject: [PATCH] simplifyTypedef: Better handling of 'typedef int RexxFunctionHandler();'. Ticket: #2348 --- lib/tokenize.cpp | 3 +++ test/testsimplifytokens.cpp | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9d75f6070..859cf0160 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1440,6 +1440,9 @@ void Tokenizer::simplifyTypedef() tok2 = tok2->tokAt(5)->link(); else if (Token::Match(tok2->next(), "* ( * %type% ) (")) tok2 = tok2->tokAt(6)->link(); + else if (Token::Match(tok2->next(), "* ( %type% [") && + Token::Match(tok2->tokAt(4)->link(), "] ) ;|=")) + tok2 = tok2->tokAt(4)->link()->next(); else { if (tok2->next()->str() == "(") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index bd3b71825..59050cddf 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -228,6 +228,7 @@ private: TEST_CASE(simplifyTypedef68); // ticket #2355 TEST_CASE(simplifyTypedef69); // ticket #2348 TEST_CASE(simplifyTypedef70); // ticket #2348 + TEST_CASE(simplifyTypedef71); // ticket #2348 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4654,13 +4655,11 @@ private: "{\n" " CompilerHook *(*compilerHookVector)(void);\n" "}VirtualMachine;\n"; - const std::string expected = "; " "struct VirtualMachine " "{ " "int ( * * ( * compilerHookVector ) ( void ) ) ( ) ; " "} ;"; - ASSERT_EQUALS(expected, sizeof_(code)); ASSERT_EQUALS("", errout.str()); } @@ -4669,17 +4668,32 @@ private: { const char code[] = "typedef int pread_f ( int ) ;\n" "pread_f *(*test_func)(char *filename);\n"; - - - - const std::string expected = "; " "int ( * ( * test_func ) ( char * filename ) ) ( int ) ;"; - ASSERT_EQUALS(expected, sizeof_(code)); ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef71() // ticket #2348 + { + { + const char code[] = "typedef int RexxFunctionHandler();\n" + "RexxFunctionHandler *(efuncs[1]);\n"; + const std::string expected = "; " + "int ( * ( efuncs [ 1 ] ) ) ( ) ;"; + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + { + const char code[] = "typedef int RexxFunctionHandler();\n" + "RexxFunctionHandler *(efuncs[]) = { NULL, NULL };\n"; + const std::string expected = "; " + "int ( * ( efuncs [ ] ) ) ( ) = { 0 , 0 } ;"; + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + } + void simplifyTypedefFunction1() { {