Fixed #1997 (operator new [] simplified wrong)

This commit is contained in:
Daniel Marjamäki 2010-08-30 21:06:22 +02:00
parent 9c499db17b
commit 7ec3c72a19
2 changed files with 13 additions and 1 deletions

View File

@ -6108,7 +6108,13 @@ bool Tokenizer::simplifyCalculations()
// Remove parantheses around variable..
// keep parantheses here: dynamic_cast<Fred *>(p);
// keep parantheses here: A operator * (int);
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") && !Token::simpleMatch(tok->previous(), "operator") && !Token::Match(tok->tokAt(-1), "* )"))
// keep parantheses here: operator new [] (size_t);
if (Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") &&
!tok->isName() &&
tok->str() != ">" &&
tok->str() != "]" &&
!Token::simpleMatch(tok->previous(), "operator") &&
!Token::simpleMatch(tok->previous(), "* )"))
{
tok->deleteNext();
tok = tok->next();

View File

@ -2456,6 +2456,12 @@ private:
ASSERT_EQUALS("x = 501 ;", tok("x = 1000 + 2 >> 1;"));
ASSERT_EQUALS("x = 125 ;", tok("x = 1000 / 2 >> 2;"));
{
// Ticket #1997
const char code[] = "void * operator new[](size_t);";
ASSERT_EQUALS("void * operator new [ ] ( size_t ) ;", tok(code));
}
}