Tokenizer::simplifyFunctionPointer: don't simplify function call. Ticket: #2873

This commit is contained in:
Daniel Marjamäki 2011-07-22 07:58:53 +02:00
parent 84ca1902a5
commit 0dd5472642
2 changed files with 21 additions and 0 deletions

View File

@ -5807,6 +5807,14 @@ void Tokenizer:: simplifyFunctionPointers()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
// #2873 - dont simplify function pointer usage here:
// (void)(xy(*p)(0));
if (Token::simpleMatch(tok, ") ("))
{
tok = tok->next()->link();
continue;
}
// check for function pointer cast
if (Token::Match(tok, "( %type% *| *| ( * ) (") ||
Token::Match(tok, "( %type% %type% *| *| ( * ) (") ||

View File

@ -284,6 +284,7 @@ private:
TEST_CASE(functionpointer1);
TEST_CASE(functionpointer2);
TEST_CASE(functionpointer3);
TEST_CASE(removeRedundantAssignment);
@ -4846,6 +4847,18 @@ private:
ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
}
void functionpointer3()
{
// Related with ticket #2873
const char code[] = "void f() {\n"
"(void)(xy(*p)(0);)"
"\n}";
const char expected[] = " void f(){"
"( void)( xy(* p)(0);)"
"}";
ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
}
void removeRedundantAssignment()
{
ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));