[PATCH] D51719: Wrapped block after case label should not be merged into a single line (Bug 38854)
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 13 00:28:44 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342116: [clang-format] Wrapped block after case label should not be merged into one line (authored by owenpan, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D51719?vs=164153&id=165208#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51719
Files:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -323,6 +323,10 @@
kwId == clang::tok::objc_synchronized)
return 0;
}
+ // Don't merge block with left brace wrapped after case labels
+ if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() &&
+ I[-1]->First->isOneOf(tok::kw_case, tok::kw_default))
+ return 0;
// 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 ||
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1064,6 +1064,32 @@
" return;\n"
"}",
getLLVMStyleWithColumns(34));
+
+ FormatStyle Style = getLLVMStyle();
+ Style.IndentCaseLabels = true;
+ Style.AllowShortBlocksOnASingleLine = false;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterControlStatement = true;
+ EXPECT_EQ("switch (n)\n"
+ "{\n"
+ " case 0:\n"
+ " {\n"
+ " return false;\n"
+ " }\n"
+ " default:\n"
+ " {\n"
+ " return true;\n"
+ " }\n"
+ "}",
+ format("switch (n) {\n"
+ " case 0: {\n"
+ " return false;\n"
+ " }\n"
+ " default: {\n"
+ " return true;\n"
+ " }\n"
+ "}",
+ Style));
}
TEST_F(FormatTest, CaseRanges) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51719.165208.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/c892c780/attachment.bin>
More information about the cfe-commits
mailing list