diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 75fb2a4c4..35f2dd721 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4763,7 +4763,9 @@ void Tokenizer::simplifyCasts() for (Token *tok = _tokens; tok; tok = tok->next()) { // #2897 : don't remove cast in such cases: // *((char *)a + 1) = 0; - if (!tok->isName() && Token::simpleMatch(tok->next(), "* (")) { + // #3596 : remove cast when casting a function pointer: + // (*(void (*)(char *))fp)(x); + if (!tok->isName() && Token::simpleMatch(tok->next(), "* (") && !Token::Match(tok->linkAt(2), ") %var%")) { tok = tok->linkAt(2); continue; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2c822a99d..69884619a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -74,6 +74,7 @@ private: TEST_CASE(removeCast7); TEST_CASE(removeCast8); TEST_CASE(removeCast9); + TEST_CASE(removeCast10); TEST_CASE(inlineasm); @@ -781,6 +782,10 @@ private: ASSERT_EQUALS("f ( ( double ) v1 * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true)); } + void removeCast10() { + ASSERT_EQUALS("; ( * f ) ( p ) ;", tokenizeAndStringify("; (*(void (*)(char *))f)(p);", true)); + } + void inlineasm() { ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));