fix #2651 function typedef with extra ()s

This commit is contained in:
Robert Reif 2011-03-15 19:24:30 -04:00
parent fa868e44ae
commit ba0b3e6451
2 changed files with 22 additions and 3 deletions

View File

@ -1234,10 +1234,17 @@ void Tokenizer::simplifyTypedef()
} }
// function: typedef ... ( .... type )( ... ); // function: typedef ... ( .... type )( ... );
else if (tok->tokAt(offset)->str() == "(" && // typedef ... (( .... type )( ... ));
Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") && else if ((tok->tokAt(offset)->str() == "(" &&
Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) 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); funcStart = tok->tokAt(offset + 1);
funcEnd = tok->tokAt(offset)->link()->tokAt(-2); funcEnd = tok->tokAt(offset)->link()->tokAt(-2);
typeName = tok->tokAt(offset)->link()->previous(); typeName = tok->tokAt(offset)->link()->previous();
@ -1256,6 +1263,8 @@ void Tokenizer::simplifyTypedef()
} }
tok = specEnd->next(); tok = specEnd->next();
} }
if (tok->str() == ")")
tok = tok->next();
} }
else if (Token::Match(tok->tokAt(offset), "( %type% (")) else if (Token::Match(tok->tokAt(offset), "( %type% ("))

View File

@ -246,6 +246,7 @@ private:
TEST_CASE(simplifyTypedef82); // ticket #2403 TEST_CASE(simplifyTypedef82); // ticket #2403
TEST_CASE(simplifyTypedef83); // ticket #2620 TEST_CASE(simplifyTypedef83); // ticket #2620
TEST_CASE(simplifyTypedef84); // ticket #2630 TEST_CASE(simplifyTypedef84); // ticket #2630
TEST_CASE(simplifyTypedef85); // ticket #2651
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4986,6 +4987,15 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); 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() void simplifyTypedefFunction1()
{ {
{ {