diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0e7a7bc7f..2516b1cd1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3102,7 +3102,15 @@ void Tokenizer::simplifyIfAddBraces() ++parlevel; else if (tempToken->str() == ")") + { + if (parlevel == 0) + { + tok->deleteThis(); + tempToken = 0; + break; + } --parlevel; + } else if (indentlevel == 0 && parlevel == 0 && tempToken->str() == ";") break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 098a045e4..3ac625337 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -70,6 +70,7 @@ private: TEST_CASE(ifAddBraces6); TEST_CASE(ifAddBraces7); TEST_CASE(ifAddBraces9); + TEST_CASE(ifAddBraces10); TEST_CASE(whileAddBraces); TEST_CASE(doWhileAddBraces); @@ -623,6 +624,14 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } + void ifAddBraces10() + { + // ticket #1361 + const char code[] = "{ DEBUG(if (x) y; else z); }"; + const char expected[] = "{ DEBUG ( if ( x ) y ; else z ) ; }"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + } + void whileAddBraces() { {