diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3fca39e8f..4218ced85 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6108,7 +6108,13 @@ bool Tokenizer::simplifyCalculations() // Remove parantheses around variable.. // keep parantheses here: dynamic_cast(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(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4e69a895d..6eba86ee3 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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)); + } }