From d4d0bc050a92e582d90fb6f21b7498714773ea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 19 Jul 2010 12:06:20 +0200 Subject: [PATCH] Fixed #1865 (Tokenizer::simplifyRedundantParantheses: wrong handling of 'operator delete') --- lib/tokenize.cpp | 5 +++-- test/testtokenize.cpp | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 21f01524b..bdb27491d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5735,8 +5735,9 @@ bool Tokenizer::simplifyRedundantParanthesis() ret = true; } - if ((Token::simpleMatch(tok->previous(), "delete (") && Token::Match(tok->link(), ") ;|,")) || - (Token::simpleMatch(tok->previous(), "; (") && Token::Match(tok->link(), ") ;"))) + if (!Token::simpleMatch(tok->tokAt(-2), "operator delete") && + Token::Match(tok->previous(), "delete|; (") && + Token::Match(tok->link(), ") ;|,")) { tok->link()->deleteThis(); tok->deleteThis(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 330ba12ea..51f0d677f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -165,13 +165,14 @@ private: TEST_CASE(simplify_function_parameters); - TEST_CASE(removeParantheses1); // Ticket #61 + TEST_CASE(removeParantheses1); // Ticket #61 TEST_CASE(removeParantheses2); TEST_CASE(removeParantheses3); TEST_CASE(removeParantheses4); // Ticket #390 TEST_CASE(removeParantheses5); // Ticket #392 TEST_CASE(removeParantheses6); TEST_CASE(removeParantheses7); + TEST_CASE(removeParantheses8); // Ticket #1865 TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -3014,6 +3015,20 @@ private: ASSERT_EQUALS(" ; delete p ; ( p ) = 0 ;", ostr.str()); } + void removeParantheses8() + { + const char code[] = "struct foo {\n" + " void operator delete(void *obj, size_t sz);\n" + "}\n"; + const std::string actual(tokenizeAndStringify(code)); + + const char expected[] = "struct foo {\n" + "void operator delete ( void * obj , size_t sz ) ;\n" + "}"; + + ASSERT_EQUALS(expected, actual); + } + void tokenize_double() { const char code[] = "void f()\n"