From 0dd547264259cd39ca817e5866e0497415397cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 Jul 2011 07:58:53 +0200 Subject: [PATCH] Tokenizer::simplifyFunctionPointer: don't simplify function call. Ticket: #2873 --- lib/tokenize.cpp | 8 ++++++++ test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 434054b50..3321ae147 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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% *| *| ( * ) (") || diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0a4110712..6ea2e8685 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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));