curdeius created this revision. curdeius added a reviewer: djasper. curdeius added a subscriber: cfe-commits. Herald added a subscriber: klimek.
This fixes bug 25192. See https://llvm.org/bugs/show_bug.cgi?id=25192. http://reviews.llvm.org/D13811 Files: lib/Format/UnwrappedLineFormatter.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6520,6 +6520,18 @@ MergeInlineOnly); } +TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLineLinux) { + FormatStyle MergeEmptyLinux = getLLVMStyle(); + MergeEmptyLinux.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + MergeEmptyLinux.BreakBeforeBraces = FormatStyle::BS_Linux; + verifyFormat("class C\n" + "{\n" + " int f() {}\n" + "};", + MergeEmptyLinux); + verifyFormat("int f() {}", MergeEmptyLinux); +} + TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { // Elaborate type variable declarations. verifyFormat("struct foo a = {bar};\nint n;"); Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -190,7 +190,7 @@ bool MergeShortFunctions = Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All || (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && - I[1]->First->is(tok::r_brace)) || + I[1]->First->isOneOf(tok::l_brace, tok::r_brace)) || (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline && TheLine->Level != 0);
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6520,6 +6520,18 @@ MergeInlineOnly); } +TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLineLinux) { + FormatStyle MergeEmptyLinux = getLLVMStyle(); + MergeEmptyLinux.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + MergeEmptyLinux.BreakBeforeBraces = FormatStyle::BS_Linux; + verifyFormat("class C\n" + "{\n" + " int f() {}\n" + "};", + MergeEmptyLinux); + verifyFormat("int f() {}", MergeEmptyLinux); +} + TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { // Elaborate type variable declarations. verifyFormat("struct foo a = {bar};\nint n;"); Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -190,7 +190,7 @@ bool MergeShortFunctions = Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All || (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && - I[1]->First->is(tok::r_brace)) || + I[1]->First->isOneOf(tok::l_brace, tok::r_brace)) || (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline && TheLine->Level != 0);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits