This revision was automatically updated to reflect the committed changes. Closed by commit rG0487f6f19cda: [clang-format] Fix short block when braking after control statement (authored by MyDeveloperDay).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D71512/new/ https://reviews.llvm.org/D71512 Files: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -606,6 +606,12 @@ verifyFormat("if CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements); + verifyFormat("if (true) { fffffffffffffffffffffff(); }", + AllowSimpleBracedStatements); + verifyFormat("if (true) {\n" + " ffffffffffffffffffffffff();\n" + "}", + AllowSimpleBracedStatements); verifyFormat("if (true) {\n" " ffffffffffffffffffffffffffffffffffffffffffffffffffffff();\n" "}", @@ -681,6 +687,13 @@ verifyFormat("if CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements); + verifyFormat("if (true) { fffffffffffffffffffffff(); }", + AllowSimpleBracedStatements); + verifyFormat("if (true)\n" + "{\n" + " ffffffffffffffffffffffff();\n" + "}", + AllowSimpleBracedStatements); verifyFormat("if (true)\n" "{\n" " ffffffffffffffffffffffffffffffffffffffffffffffffffffff();\n" @@ -745,7 +758,9 @@ Style.BreakBeforeBraces = FormatStyle::BS_Allman; EXPECT_EQ("#define A \\\n" " if (HANDLEwernufrnuLwrmviferuvnierv) \\\n" - " { RET_ERR1_ANUIREUINERUIFNIOAerwfwrvnuier; }\n" + " { \\\n" + " RET_ERR1_ANUIREUINERUIFNIOAerwfwrvnuier; \\\n" + " }\n" "X;", format("#define A \\\n" " if (HANDLEwernufrnuLwrmviferuvnierv) { \\\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -342,21 +342,6 @@ ? 1 : 0; } - // Try to merge either empty or one-line block if is precedeed by control - // statement token - if (TheLine->First->is(tok::l_brace) && TheLine->First == TheLine->Last && - I != AnnotatedLines.begin() && - I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { - unsigned MergedLines = 0; - if (Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never) { - MergedLines = tryMergeSimpleBlock(I - 1, E, Limit); - // If we managed to merge the block, discard the first merged line - // since we are merging starting from I. - if (MergedLines > 0) - --MergedLines; - } - return MergedLines; - } // Don't merge block with left brace wrapped after ObjC special blocks if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() && I[-1]->First->is(tok::at) && I[-1]->First->Next) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -606,6 +606,12 @@ verifyFormat("if CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements); + verifyFormat("if (true) { fffffffffffffffffffffff(); }", + AllowSimpleBracedStatements); + verifyFormat("if (true) {\n" + " ffffffffffffffffffffffff();\n" + "}", + AllowSimpleBracedStatements); verifyFormat("if (true) {\n" " ffffffffffffffffffffffffffffffffffffffffffffffffffffff();\n" "}", @@ -681,6 +687,13 @@ verifyFormat("if CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements); + verifyFormat("if (true) { fffffffffffffffffffffff(); }", + AllowSimpleBracedStatements); + verifyFormat("if (true)\n" + "{\n" + " ffffffffffffffffffffffff();\n" + "}", + AllowSimpleBracedStatements); verifyFormat("if (true)\n" "{\n" " ffffffffffffffffffffffffffffffffffffffffffffffffffffff();\n" @@ -745,7 +758,9 @@ Style.BreakBeforeBraces = FormatStyle::BS_Allman; EXPECT_EQ("#define A \\\n" " if (HANDLEwernufrnuLwrmviferuvnierv) \\\n" - " { RET_ERR1_ANUIREUINERUIFNIOAerwfwrvnuier; }\n" + " { \\\n" + " RET_ERR1_ANUIREUINERUIFNIOAerwfwrvnuier; \\\n" + " }\n" "X;", format("#define A \\\n" " if (HANDLEwernufrnuLwrmviferuvnierv) { \\\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -342,21 +342,6 @@ ? 1 : 0; } - // Try to merge either empty or one-line block if is precedeed by control - // statement token - if (TheLine->First->is(tok::l_brace) && TheLine->First == TheLine->Last && - I != AnnotatedLines.begin() && - I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { - unsigned MergedLines = 0; - if (Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never) { - MergedLines = tryMergeSimpleBlock(I - 1, E, Limit); - // If we managed to merge the block, discard the first merged line - // since we are merging starting from I. - if (MergedLines > 0) - --MergedLines; - } - return MergedLines; - } // Don't merge block with left brace wrapped after ObjC special blocks if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() && I[-1]->First->is(tok::at) && I[-1]->First->Next) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits