aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/UnwrappedLineFormatter.cpp4
-rw-r--r--unittests/Format/FormatTest.cpp26
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp
index f0d93a1f4f..43d71504ca 100644
--- a/lib/Format/UnwrappedLineFormatter.cpp
+++ b/lib/Format/UnwrappedLineFormatter.cpp
@@ -323,6 +323,10 @@ private:
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 ||
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index e7c467547a..70bc9e0ed7 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1064,6 +1064,32 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
" 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) {