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;
}
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();

View File

@ -172,6 +172,7 @@ private:
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"