Improved typedef simplification of function pointers

This commit is contained in:
Robert Reif 2010-01-21 07:51:08 +01:00 committed by Daniel Marjamäki
parent a6e81c2ee7
commit e9e64033e7
2 changed files with 17 additions and 2 deletions

View File

@ -680,8 +680,8 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->next();
// skip over typedef parameter
while (!Token::Match(tok2->next(), "=|{|;"))
tok2 = tok2->next();
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
tok2->insertToken(")");
tok2 = tok2->next();

View File

@ -157,6 +157,7 @@ private:
TEST_CASE(simplifyTypedef20);
TEST_CASE(simplifyTypedef21);
TEST_CASE(simplifyTypedef22);
TEST_CASE(simplifyTypedef23);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -2710,6 +2711,20 @@ private:
}
}
void simplifyTypedef23()
{
const char code[] = "typedef bool (*Callback) (int i);\n"
"void addCallback(Callback callback) { }\n"
"void addCallback1(Callback callback, int j) { }";
const char expected[] =
"; "
"void addCallback ( bool ( * callback ) ( int i ) ) { } "
"void addCallback1 ( bool ( * callback ) ( int i ) , int j ) { }";
ASSERT_EQUALS(expected, tok(code, false));
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));