]> granicus.if.org Git - clang/commitdiff
Fix indentation for case: // comment.
authorDaniel Jasper <djasper@google.com>
Tue, 19 Mar 2013 18:33:58 +0000 (18:33 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 19 Mar 2013 18:33:58 +0000 (18:33 +0000)
Before:
switch (x) {
case 1:
    // Do amazing stuff
    {
  g();
  f();
}
}

After:
switch (x) {
case 1:
  // Do amazing stuff
  {
    g();
    f();
  }
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177420 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index cdd77759fd2cd54a764bbd659d4a7afaf6ee8eab..a438a53c370f891fe3f89606b8f30886915f2d95 100644 (file)
@@ -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.
index a3afbee916e94f28b67081a538e7c4ca393194db..a940f7092fc4f4a0a104c9a26d055455ec28a123 100644 (file)
@@ -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"