diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bd51f98da..2dff8f16a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6618,6 +6618,7 @@ bool Tokenizer::simplifyCalculations() // Remove parentheses around variable.. // keep parentheses here: dynamic_cast(p); // keep parentheses here: A operator * (int); + // keep parentheses here: int ( * * ( * compilerHookVector ) (void) ) ( ) ; // keep parentheses here: operator new [] (size_t); // keep parentheses here: Functor()(a ... ) if (Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") && @@ -6626,6 +6627,7 @@ bool Tokenizer::simplifyCalculations() tok->str() != "]" && !Token::simpleMatch(tok->previous(), "operator") && !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 f777abf18..057be6bf5 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4645,6 +4645,24 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef69() // ticket #2348 + { + const char code[] = "typedef int (*CompilerHook)();\n" + "typedef struct VirtualMachine \n" + "{\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()); + } + void simplifyTypedefFunction1() { {