Formatter: After case blocks, "break" goes on the same line as the "}", PR14907.

Before:
switch (foo) {
case a: {
  int a = g();
  h(a);
}
  break;
}

Now:
switch (foo) {
case a: {
  int a = g();
  h(a);
} break;
}



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172789 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 4b994e3..999d621 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -952,10 +952,10 @@
             return false;
         }
         break;
-      case tok::l_paren: {
+      case tok::l_paren:
         if (!parseParens())
           return false;
-      } break;
+        break;
       case tok::l_square:
         if (!parseSquare())
           return false;
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 89ab0ed..1f71b5b 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -487,6 +487,8 @@
     --Line->Level;
   if (FormatTok.Tok.is(tok::l_brace)) {
     parseBlock();
+    if (FormatTok.Tok.is(tok::kw_break))
+      parseStructuralElement(); // "break;" after "}" goes on the same line.
   }
   addUnwrappedLine();
   Line->Level = OldLineLevel;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index c3fef1d..2a2bb3f 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -274,6 +274,32 @@
                "  break;\n"
                "}\n"
                "}");
+  verifyFormat("switch (x) {\n"
+               "case 1: {\n"
+               "  f();\n"
+               "  {\n"
+               "    g();\n"
+               "    h();\n"
+               "  }\n"
+               "  break;\n"
+               "}\n"
+               "}");
+  verifyFormat("switch (x) {\n"
+               "case 1: {\n"
+               "  f();\n"
+               "  if (foo) {\n"
+               "    g();\n"
+               "    h();\n"
+               "  }\n"
+               "  break;\n"
+               "}\n"
+               "}");
+  verifyFormat("switch (x) {\n"
+               "case 1: {\n"
+               "  f();\n"
+               "  g();\n"
+               "} break;\n"
+               "}");
   verifyFormat("switch (test)\n"
                "  ;");
   verifyGoogleFormat("switch (x) {\n"