diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 494ea9cc3..17e8fc170 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -1727,7 +1727,7 @@ bool Tokenizer::simplifyIfAddBraces() else if (tempToken->str() == "}") { --indentlevel; - if (indentlevel == 0) + if (indentlevel == 0 && parlevel == 0) break; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ab3b118d6..0a8664f4e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -79,6 +79,7 @@ private: TEST_CASE(ifAddBraces4); TEST_CASE(ifAddBraces5); TEST_CASE(ifAddBraces6); + TEST_CASE(ifAddBraces7); TEST_CASE(whileAddBraces); @@ -444,6 +445,22 @@ private: ASSERT_EQUALS("if ( )", tokenizeAndStringify(code, true)); } + void ifAddBraces7() + { + const char code[] = "void f()\n" + "{\n" + "int a;\n" + "if( a )\n" + " ({a=4;}),({a=5;});\n" + "}\n"; + ASSERT_EQUALS("void f ( )\n" + "{\n" + "int a ;\n" + "if ( a ) {\n" + "( { a = 4 ; } ) , ( { a = 5 ; } ) ; }\n" + "}", tokenizeAndStringify(code, true)); + } + void whileAddBraces() { {