diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index aa5b54357..a3f9c505c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4604,7 +4604,9 @@ void Tokenizer::simplifyCasts() for (Token *tok = _tokens; tok; tok = tok->next()) { while (Token::Match(tok->next(), "( %type% *| ) *|&| %var%") || - Token::Match(tok->next(), "( %type% %type% *| ) *|&| %var%")) + Token::Match(tok->next(), "( %type% %type% *| ) *|&| %var%") || + (!tok->isName() && (Token::Match(tok->next(), "( %type% * ) (") || + Token::Match(tok->next(), "( %type% %type% * ) (")))) { if (tok->isName() && tok->str() != "return") break; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 23596bce2..33723e5df 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -474,7 +474,7 @@ private: // dealloc; ASSERT_EQUALS(";;dealloc;", getcode("char *s; free(s);", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; free((void *)s);", "s")); - TODO_ASSERT_EQUALS(";;dealloc;", getcode("char *s; free((void *)(s));", "s")); + ASSERT_EQUALS(";;dealloc;", getcode("char *s; free((void *)(s));", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; free(reinterpret_cast(s));", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete s;", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (s);", "s")); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4dc84603c..12ebc0ca2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -62,6 +62,7 @@ private: TEST_CASE(removeCast3); TEST_CASE(removeCast4); TEST_CASE(removeCast5); + TEST_CASE(removeCast6); TEST_CASE(inlineasm); @@ -532,6 +533,12 @@ private: ASSERT_EQUALS("a . data = f ;", tokenizeAndStringify("a->data = reinterpret_cast(static_cast(f));", true)); } + void removeCast6() + { + // ticket #2103 + ASSERT_EQUALS("if ( ! x )", tokenizeAndStringify("if (x == (char *) ((void *)0))", true)); + } + void inlineasm() { ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";asm { mov ax,bx };"));