Tokenizer: Fixed problem in Tokenizer::simplifyRedundantParanthesis when simplifying 'void delete(double num);'

This commit is contained in:
Daniel Marjamäki 2010-09-05 07:53:43 +02:00
parent a2b4e5641f
commit 51bc784537
2 changed files with 10 additions and 6 deletions

View File

@ -6068,6 +6068,7 @@ bool Tokenizer::simplifyRedundantParanthesis()
if (!Token::simpleMatch(tok->tokAt(-2), "operator delete") && if (!Token::simpleMatch(tok->tokAt(-2), "operator delete") &&
Token::Match(tok->previous(), "delete|; (") && Token::Match(tok->previous(), "delete|; (") &&
(tok->strAt(-1) != "delete" || tok->next()->varId() > 0) &&
Token::Match(tok->link(), ") ;|,")) Token::Match(tok->link(), ") ;|,"))
{ {
tok->link()->deleteThis(); tok->link()->deleteThis();

View File

@ -44,16 +44,13 @@ private:
TEST_CASE(tokenize3); TEST_CASE(tokenize3);
TEST_CASE(tokenize4); TEST_CASE(tokenize4);
TEST_CASE(tokenize5); TEST_CASE(tokenize5);
TEST_CASE(tokenize6); TEST_CASE(tokenize6); // array access. replace "*(p+1)" => "p[1]"
TEST_CASE(tokenize7); TEST_CASE(tokenize7);
TEST_CASE(tokenize8); TEST_CASE(tokenize8);
TEST_CASE(tokenize9); TEST_CASE(tokenize9);
TEST_CASE(tokenize10); TEST_CASE(tokenize10);
TEST_CASE(tokenize11); TEST_CASE(tokenize11);
// array access. replace "*(p+1)" => "p[1]"
TEST_CASE(tokenize6);
// don't freak out when the syntax is wrong // don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax); TEST_CASE(wrong_syntax);
@ -191,6 +188,7 @@ private:
TEST_CASE(removeParantheses6); TEST_CASE(removeParantheses6);
TEST_CASE(removeParantheses7); TEST_CASE(removeParantheses7);
TEST_CASE(removeParantheses8); // Ticket #1865 TEST_CASE(removeParantheses8); // Ticket #1865
TEST_CASE(removeParantheses9); // Ticket #1962
TEST_CASE(tokenize_double); TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings); TEST_CASE(tokenize_strings);
@ -3294,7 +3292,7 @@ private:
void removeParantheses7() void removeParantheses7()
{ {
const char code[] = ";(delete(p), (p)=0);"; const char code[] = ";char *p; (delete(p), (p)=0);";
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer;
@ -3306,7 +3304,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(" ; delete p ; ( p ) = 0 ;", ostr.str()); ASSERT_EQUALS(" ; char * p ; delete p ; ( p ) = 0 ;", ostr.str());
} }
void removeParantheses8() void removeParantheses8()
@ -3323,6 +3321,11 @@ private:
ASSERT_EQUALS(expected, actual); ASSERT_EQUALS(expected, actual);
} }
void removeParantheses9()
{
ASSERT_EQUALS("void delete ( double num ) ;", tokenizeAndStringify("void delete(double num);", false));
}
void tokenize_double() void tokenize_double()
{ {
const char code[] = "void f()\n" const char code[] = "void f()\n"