This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG07fe45130546: [clang-format] Fix SplitEmptyRecord affecting SplitEmptyFunction. (authored by curdeius).
Changed prior to commit: https://reviews.llvm.org/D116049?vs=395477&id=395683#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116049/new/ https://reviews.llvm.org/D116049 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 @@ -12200,6 +12200,38 @@ "}", Style); } + +TEST_F(FormatTest, SplitEmptyFunctionButNotRecord) { + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + Style.BraceWrapping.SplitEmptyFunction = true; + Style.BraceWrapping.SplitEmptyRecord = false; + Style.ColumnLimit = 40; + + verifyFormat("class C {};", Style); + verifyFormat("struct C {};", Style); + verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " int bbbbbbbbbbbbbbbbbbbbbbbb)\n" + "{\n" + "}", + Style); + verifyFormat("class C {\n" + " C()\n" + " : aaaaaaaaaaaaaaaaaaaaaaaaaaaa(),\n" + " bbbbbbbbbbbbbbbbbbb()\n" + " {\n" + " }\n" + " void\n" + " m(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " int bbbbbbbbbbbbbbbbbbbbbbbb)\n" + " {\n" + " }\n" + "};", + Style); +} + TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { FormatStyle Style = getLLVMStyle(); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -393,11 +393,17 @@ // Try to merge a block with left brace wrapped that wasn't yet covered if (TheLine->Last->is(tok::l_brace)) { - return !Style.BraceWrapping.AfterFunction || - (I[1]->First->is(tok::r_brace) && - !Style.BraceWrapping.SplitEmptyRecord) - ? tryMergeSimpleBlock(I, E, Limit) - : 0; + bool ShouldMerge = false; + if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) { + ShouldMerge = !Style.BraceWrapping.AfterClass || + (I[1]->First->is(tok::r_brace) && + !Style.BraceWrapping.SplitEmptyRecord); + } else { + ShouldMerge = !Style.BraceWrapping.AfterFunction || + (I[1]->First->is(tok::r_brace) && + !Style.BraceWrapping.SplitEmptyFunction); + } + return ShouldMerge ? tryMergeSimpleBlock(I, E, Limit) : 0; } // Try to merge a function block with left brace wrapped if (I[1]->First->is(TT_FunctionLBrace) &&
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12200,6 +12200,38 @@ "}", Style); } + +TEST_F(FormatTest, SplitEmptyFunctionButNotRecord) { + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + Style.BraceWrapping.SplitEmptyFunction = true; + Style.BraceWrapping.SplitEmptyRecord = false; + Style.ColumnLimit = 40; + + verifyFormat("class C {};", Style); + verifyFormat("struct C {};", Style); + verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " int bbbbbbbbbbbbbbbbbbbbbbbb)\n" + "{\n" + "}", + Style); + verifyFormat("class C {\n" + " C()\n" + " : aaaaaaaaaaaaaaaaaaaaaaaaaaaa(),\n" + " bbbbbbbbbbbbbbbbbbb()\n" + " {\n" + " }\n" + " void\n" + " m(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " int bbbbbbbbbbbbbbbbbbbbbbbb)\n" + " {\n" + " }\n" + "};", + Style); +} + TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { FormatStyle Style = getLLVMStyle(); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -393,11 +393,17 @@ // Try to merge a block with left brace wrapped that wasn't yet covered if (TheLine->Last->is(tok::l_brace)) { - return !Style.BraceWrapping.AfterFunction || - (I[1]->First->is(tok::r_brace) && - !Style.BraceWrapping.SplitEmptyRecord) - ? tryMergeSimpleBlock(I, E, Limit) - : 0; + bool ShouldMerge = false; + if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) { + ShouldMerge = !Style.BraceWrapping.AfterClass || + (I[1]->First->is(tok::r_brace) && + !Style.BraceWrapping.SplitEmptyRecord); + } else { + ShouldMerge = !Style.BraceWrapping.AfterFunction || + (I[1]->First->is(tok::r_brace) && + !Style.BraceWrapping.SplitEmptyFunction); + } + return ShouldMerge ? tryMergeSimpleBlock(I, E, Limit) : 0; } // Try to merge a function block with left brace wrapped if (I[1]->First->is(TT_FunctionLBrace) &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits