Fixed #1865 (Tokenizer::simplifyRedundantParantheses: wrong handling of 'operator delete')

This commit is contained in:
Daniel Marjamäki 2010-07-19 12:06:20 +02:00
parent 7ef0296f97
commit d4d0bc050a
2 changed files with 19 additions and 3 deletions

View File

@ -5735,8 +5735,9 @@ bool Tokenizer::simplifyRedundantParanthesis()
ret = true; ret = true;
} }
if ((Token::simpleMatch(tok->previous(), "delete (") && Token::Match(tok->link(), ") ;|,")) || if (!Token::simpleMatch(tok->tokAt(-2), "operator delete") &&
(Token::simpleMatch(tok->previous(), "; (") && Token::Match(tok->link(), ") ;"))) Token::Match(tok->previous(), "delete|; (") &&
Token::Match(tok->link(), ") ;|,"))
{ {
tok->link()->deleteThis(); tok->link()->deleteThis();
tok->deleteThis(); tok->deleteThis();

View File

@ -165,13 +165,14 @@ private:
TEST_CASE(simplify_function_parameters); TEST_CASE(simplify_function_parameters);
TEST_CASE(removeParantheses1); // Ticket #61 TEST_CASE(removeParantheses1); // Ticket #61
TEST_CASE(removeParantheses2); TEST_CASE(removeParantheses2);
TEST_CASE(removeParantheses3); TEST_CASE(removeParantheses3);
TEST_CASE(removeParantheses4); // Ticket #390 TEST_CASE(removeParantheses4); // Ticket #390
TEST_CASE(removeParantheses5); // Ticket #392 TEST_CASE(removeParantheses5); // Ticket #392
TEST_CASE(removeParantheses6); TEST_CASE(removeParantheses6);
TEST_CASE(removeParantheses7); TEST_CASE(removeParantheses7);
TEST_CASE(removeParantheses8); // Ticket #1865
TEST_CASE(tokenize_double); TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings); TEST_CASE(tokenize_strings);
@ -3014,6 +3015,20 @@ private:
ASSERT_EQUALS(" ; delete p ; ( p ) = 0 ;", ostr.str()); 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() void tokenize_double()
{ {
const char code[] = "void f()\n" const char code[] = "void f()\n"