typedef: fix typedef simplification. ticket: #2348

This commit is contained in:
Robert Reif 2010-12-28 21:21:13 +01:00 committed by Daniel Marjamäki
parent bdf0cb7115
commit e82b1f8946
2 changed files with 20 additions and 0 deletions

View File

@ -6618,6 +6618,7 @@ bool Tokenizer::simplifyCalculations()
// Remove parentheses around variable.. // Remove parentheses around variable..
// keep parentheses here: dynamic_cast<Fred *>(p); // keep parentheses here: dynamic_cast<Fred *>(p);
// keep parentheses here: A operator * (int); // keep parentheses here: A operator * (int);
// keep parentheses here: int ( * * ( * compilerHookVector ) (void) ) ( ) ;
// keep parentheses here: operator new [] (size_t); // keep parentheses here: operator new [] (size_t);
// keep parentheses here: Functor()(a ... ) // keep parentheses here: Functor()(a ... )
if (Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") && if (Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") &&
@ -6626,6 +6627,7 @@ bool Tokenizer::simplifyCalculations()
tok->str() != "]" && tok->str() != "]" &&
!Token::simpleMatch(tok->previous(), "operator") && !Token::simpleMatch(tok->previous(), "operator") &&
!Token::simpleMatch(tok->previous(), "* )") && !Token::simpleMatch(tok->previous(), "* )") &&
!Token::Match(tok->tokAt(-2), "* %var% )") &&
!Token::Match(tok->tokAt(-2), "%type% ( ) ( %var%") !Token::Match(tok->tokAt(-2), "%type% ( ) ( %var%")
) )
{ {

View File

@ -4645,6 +4645,24 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef69() // ticket #2348
{
const char code[] = "typedef int (*CompilerHook)();\n"
"typedef struct VirtualMachine \n"
"{\n"
" CompilerHook *(*compilerHookVector)(void);\n"
"}VirtualMachine;\n";
const std::string expected = "; "
"struct VirtualMachine "
"{ "
"int ( * * ( * compilerHookVector ) ( void ) ) ( ) ; "
"} ;";
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {