From 137d0e2ba7142c645837f352c5dadbf16517c0bc Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 29 Dec 2010 09:18:41 +0100 Subject: [PATCH] typedef: fixed problem with 'typedef int pread_f(int);'. ticket: #2348 --- lib/tokenize.cpp | 4 ++++ test/testsimplifytokens.cpp | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2dff8f16a..3efb06e2f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1438,6 +1438,8 @@ void Tokenizer::simplifyTypedef() { if (Token::Match(tok2->next(), "( * %type% ) (")) tok2 = tok2->tokAt(5)->link(); + else if (Token::Match(tok2->next(), "* ( * %type% ) (")) + tok2 = tok2->tokAt(6)->link(); else { if (tok2->next()->str() == "(") @@ -6618,6 +6620,7 @@ bool Tokenizer::simplifyCalculations() // Remove parentheses around variable.. // keep parentheses here: dynamic_cast(p); // keep parentheses here: A operator * (int); + // keep parentheses here: int ( * ( * f ) ( ... ) ) (int) ; // keep parentheses here: int ( * * ( * compilerHookVector ) (void) ) ( ) ; // keep parentheses here: operator new [] (size_t); // keep parentheses here: Functor()(a ... ) @@ -6627,6 +6630,7 @@ bool Tokenizer::simplifyCalculations() tok->str() != "]" && !Token::simpleMatch(tok->previous(), "operator") && !Token::simpleMatch(tok->previous(), "* )") && + !Token::simpleMatch(tok->previous(), ") )") && !Token::Match(tok->tokAt(-2), "* %var% )") && !Token::Match(tok->tokAt(-2), "%type% ( ) ( %var%") ) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 057be6bf5..bd3b71825 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -226,6 +226,8 @@ private: TEST_CASE(simplifyTypedef66); // ticket #2341 TEST_CASE(simplifyTypedef67); // ticket #2354 TEST_CASE(simplifyTypedef68); // ticket #2355 + TEST_CASE(simplifyTypedef69); // ticket #2348 + TEST_CASE(simplifyTypedef70); // ticket #2348 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4663,6 +4665,21 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef70() // ticket #2348 + { + 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 simplifyTypedefFunction1() { {