diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 734a5bcdd..3d34aa61f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1234,10 +1234,17 @@ void Tokenizer::simplifyTypedef() } // function: typedef ... ( .... type )( ... ); - else if (tok->tokAt(offset)->str() == "(" && - Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") && - Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) + // typedef ... (( .... type )( ... )); + else if ((tok->tokAt(offset)->str() == "(" && + Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") && + Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) || + (Token::simpleMatch(tok->tokAt(offset), "( (") && + Token::Match(tok->tokAt(offset + 1)->link()->previous(), "%type% ) (") && + Token::Match(tok->tokAt(offset + 1)->link()->next()->link(), ") const|volatile| )"))) { + if (tok->strAt(offset + 1) == "(") + offset++; + funcStart = tok->tokAt(offset + 1); funcEnd = tok->tokAt(offset)->link()->tokAt(-2); typeName = tok->tokAt(offset)->link()->previous(); @@ -1256,6 +1263,8 @@ void Tokenizer::simplifyTypedef() } tok = specEnd->next(); } + if (tok->str() == ")") + tok = tok->next(); } else if (Token::Match(tok->tokAt(offset), "( %type% (")) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 74adc52af..ae77e430a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -246,6 +246,7 @@ private: TEST_CASE(simplifyTypedef82); // ticket #2403 TEST_CASE(simplifyTypedef83); // ticket #2620 TEST_CASE(simplifyTypedef84); // ticket #2630 + TEST_CASE(simplifyTypedef85); // ticket #2651 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4986,6 +4987,15 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } + void simplifyTypedef85() // ticket #2651 + { + const char code[] = "typedef FOO ((BAR)(void, int, const int, int*));\n"; + const char expected[] = ";"; + checkSimplifyTypedef(code); + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {