Fixed #2354 (simplifyTypedef: function pointers are not simplified into valid code)

This commit is contained in:
Robert Reif 2010-12-28 08:01:32 +01:00 committed by Daniel Marjamäki
parent 58ddb3b0ab
commit 1b92eeae1e
2 changed files with 25 additions and 1 deletions

View File

@ -1309,8 +1309,17 @@ void Tokenizer::simplifyTypedef()
while (Token::Match(tok2, "%var% ::"))
tok2 = tok2->tokAt(2);
if (tok2->str() == "(" &&
tok2->link()->next()->str() == "(")
{
tok2 = tok2->link();
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
}
// skip over typedef parameter
if (tok2->next()->str() == "(")
else if (tok2->next()->str() == "(")
{
tok2 = tok2->next()->link();

View File

@ -224,6 +224,7 @@ private:
TEST_CASE(simplifyTypedef64);
TEST_CASE(simplifyTypedef65); // ticket #2314
TEST_CASE(simplifyTypedef66); // ticket #2341
TEST_CASE(simplifyTypedef67); // ticket #2354
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4620,6 +4621,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef67() // ticket #2354
{
const char code[] = "typedef int ( * Function ) ( ) ;\n"
"void f ( ) {\n"
" ((Function * (*) (char *, char *, int, int)) global[6]) ( \"assoc\", \"eggdrop\", 106, 0);\n"
"}\n";
const std::string expected = "; "
"void f ( ) { "
"( ( int ( * * ( * ) ( char * , char * , int , int ) ) ( ) ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; "
"}";
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{