diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 16343d9ad..51fe6801f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7162,7 +7162,7 @@ bool Tokenizer::simplifyRedundantParentheses() ret = true; } - if (isCPP() && Token::simpleMatch(tok->previous(), "new (") && Token::Match(tok->link(), ") [;,{}[]")) { + if (isCPP() && Token::Match(tok->tokAt(-2), "[;{}=(] new (") && Token::Match(tok->link(), ") [;,{}[]")) { // Remove the parentheses in "new (type)" constructs tok->link()->deleteThis(); tok->deleteThis(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 84bb26bdf..2d20e79fb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3465,6 +3465,12 @@ private: static char exp[] = "list < int > * f [ 1 ] = { new list < int > } ;"; ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } + // don't remove parentheses in operator new overload + { + static char code[] = "void *operator new(__SIZE_TYPE__, int);"; + static char exp[] = "void * operatornew ( __SIZE_TYPE__ , int ) ;"; + ASSERT_EQUALS(exp, tokenizeAndStringify(code)); + } } void tokenize_double() {