diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b38d22f33..03473f68f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4962,7 +4962,7 @@ bool Tokenizer::simplifyIfAddBraces() { for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) { - if (tok->str() == "(") + if (tok->str() == "(" && !Token::Match(tok->previous(), "[;{}]")) { tok = tok->link(); continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9bb27e51d..7557f396d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5705,6 +5705,15 @@ private: { tokenizeAndStringify("if()x"); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + + // ticket #2873 + { + const char code[] = "void f() { " + "( { if(*p) (*p) = x(); } ) " + "}"; + ASSERT_EQUALS("void f ( ) { ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }", + tokenizeAndStringify(code)); + } } };