Fixed #1297 (typedef causes internal error in vlc/modules/access/imem.c)
This commit is contained in:
parent
d4b13eee9f
commit
9f853cb164
|
@ -620,6 +620,13 @@ void Tokenizer::simplifyTypedef()
|
|||
|
||||
if (simplifyType)
|
||||
{
|
||||
bool inCast = false;
|
||||
|
||||
if ((tok2->previous()->str() == "(" && tok2->next()->str() == ")") ||
|
||||
(Token::Match(tok2->tokAt(-2), "static_cast <") &&
|
||||
Token::Match(tok2->next(), "> (")))
|
||||
inCast = true;
|
||||
|
||||
if (start && end && !functionPtr)
|
||||
{
|
||||
tok2->str(start->str());
|
||||
|
@ -673,11 +680,15 @@ void Tokenizer::simplifyTypedef()
|
|||
Token *tok3 = tok2;
|
||||
tok2->insertToken("*");
|
||||
tok2 = tok2->next();
|
||||
tok2 = tok2->next();
|
||||
|
||||
// skip over typedef parameter
|
||||
if (tok2->next()->str() == "(")
|
||||
tok2 = tok2->next()->link();
|
||||
if (!inCast)
|
||||
{
|
||||
tok2 = tok2->next();
|
||||
|
||||
// skip over typedef parameter
|
||||
if (tok2->next()->str() == "(")
|
||||
tok2 = tok2->next()->link();
|
||||
}
|
||||
|
||||
tok2->insertToken(")");
|
||||
tok2 = tok2->next();
|
||||
|
|
|
@ -158,6 +158,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef21);
|
||||
TEST_CASE(simplifyTypedef22);
|
||||
TEST_CASE(simplifyTypedef23);
|
||||
TEST_CASE(simplifyTypedef24);
|
||||
TEST_CASE(reverseArraySyntax)
|
||||
TEST_CASE(simplify_numeric_condition)
|
||||
|
||||
|
@ -2760,6 +2761,53 @@ private:
|
|||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
void simplifyTypedef24()
|
||||
{
|
||||
{
|
||||
const char code[] = "typedef int (*fp)();\n"
|
||||
"void g( fp f )\n"
|
||||
"{\n"
|
||||
" fp f2 = (fp)f;\n"
|
||||
"}";
|
||||
|
||||
const char expected[] =
|
||||
"; "
|
||||
"void g ( int ( * f ) ( ) ) "
|
||||
"{ "
|
||||
"int ( * f2 ) ( ) = ( int ( * ) ( ) ) f ; "
|
||||
"}";
|
||||
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
|
||||
// TODO: the definition and assignment should be split up
|
||||
const char todo[] =
|
||||
"; "
|
||||
"void g ( fp f ) "
|
||||
"{ "
|
||||
"int ( * f2 ) ( ) ; f2 = ( int ( * ) ( ) ) f ; "
|
||||
"}";
|
||||
|
||||
TODO_ASSERT_EQUALS(todo, tok(code, false));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "typedef int (*fp)();\n"
|
||||
"void g( fp f )\n"
|
||||
"{\n"
|
||||
" fp f2 = static_cast<fp>(f);\n"
|
||||
"}";
|
||||
|
||||
const char expected[] =
|
||||
"; "
|
||||
"void g ( int ( * f ) ( ) ) "
|
||||
"{ "
|
||||
"int ( * f2 ) ( ) = static_cast < int ( * ) ( ) > ( f ) ; "
|
||||
"}";
|
||||
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
}
|
||||
|
||||
void reverseArraySyntax()
|
||||
{
|
||||
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
|
||||
|
|
Loading…
Reference in New Issue