[PATCH] D13811: [clang-format] AllowShortFunctionsOnASingleLine: true/Empty didn't work with BreakBeforeBraces: Linux/Allman.
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 01:30:15 PDT 2015
curdeius updated this revision to Diff 37832.
curdeius added a comment.
- AllowShortFunctionsOnASingleLine: true didn't work with BreakBeforeBraces: Linux/Allman.
- Add test checking that non-empty functions in styles with `BraceWrapping.AfterFunction = true` don't get merged into one line. Fix the merge condition.
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
@@ -6518,6 +6518,21 @@
" return 42;\n"
"}",
MergeInlineOnly);
+
+ FormatStyle MergeEmptyCustom = getLLVMStyle();
+ MergeEmptyCustom.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
+ MergeEmptyCustom.BreakBeforeBraces = FormatStyle::BS_Custom;
+ MergeEmptyCustom.BraceWrapping.AfterFunction = true;
+ verifyFormat("class C {\n"
+ " int f() {}\n"
+ "};",
+ MergeEmptyCustom);
+ verifyFormat("int f() {}", MergeEmptyCustom);
+ verifyFormat("int f()\n"
+ "{\n"
+ " return 0;\n"
+ "}",
+ MergeEmptyCustom);
}
TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -185,14 +185,18 @@
? 0
: Limit - TheLine->Last->TotalLength;
+ bool EmptyFunction =
+ (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty) &&
+ (((Style.BraceWrapping.AfterFunction && (I + 2 != E)) ? I[2] : I[1])
+ ->First->is(tok::r_brace));
// FIXME: TheLine->Level != 0 might or might not be the right check to do.
// If necessary, change to something smarter.
+ bool InlineFunction =
+ (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline) &&
+ (TheLine->Level != 0);
bool MergeShortFunctions =
Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
- (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
- I[1]->First->is(tok::r_brace)) ||
- (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&
- TheLine->Level != 0);
+ EmptyFunction || InlineFunction;
if (TheLine->Last->is(TT_FunctionLBrace) &&
TheLine->First != TheLine->Last) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13811.37832.patch
Type: text/x-patch
Size: 2183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151020/4ee772f0/attachment.bin>
More information about the cfe-commits
mailing list