aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/UnwrappedLineParser.cpp2
-rw-r--r--unittests/Format/FormatTest.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index cdd77759fd..a438a53c37 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -576,7 +576,7 @@ void UnwrappedLineParser::parseLabel() {
unsigned OldLineLevel = Line->Level;
if (Line->Level > 0)
--Line->Level;
- if (FormatTok.Tok.is(tok::l_brace)) {
+ if (CommentsBeforeNextToken.empty() && FormatTok.Tok.is(tok::l_brace)) {
parseBlock(/*MustBeDeclaration=*/ false);
if (FormatTok.Tok.is(tok::kw_break))
parseStructuralElement(); // "break;" after "}" goes on the same line.
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index a3afbee916..a940f7092f 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -432,6 +432,15 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
"case 1:\n"
" f();\n"
"}");
+ verifyFormat("switch (x) {\n"
+ "case 1:\n"
+ " // Do amazing stuff\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ " break;\n"
+ "}");
verifyGoogleFormat("switch (x) {\n"
" case 1:\n"