]> granicus.if.org Git - clang/commitdiff
clang-format: Fix merging short case labels with comments.
authorDaniel Jasper <djasper@google.com>
Mon, 21 Sep 2015 09:50:01 +0000 (09:50 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 21 Sep 2015 09:50:01 +0000 (09:50 +0000)
This fixes llvm.org/PR24877.

Patch by Benjamin Daly, thank you!

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

lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp

index 20298d33947b906b8fd5e7ce222a9e340cb3b9f9..7e1fc3b1dd530234928ce187357df393de27ccd6 100644 (file)
@@ -305,7 +305,8 @@ private:
       if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
         break;
       if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
-                               tok::kw_while, tok::comment))
+                               tok::kw_while, tok::comment) ||
+          Line->Last->is(tok::comment))
         return 0;
       Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
     }
index cda8ce4510a4a41f568a5f94ed30b1f803a8d620..e392cf880c254793fc44eb924734e6e2779b9302 100644 (file)
@@ -756,6 +756,9 @@ TEST_F(FormatTest, ShortCaseLabels) {
                "case 7:\n"
                "  // comment\n"
                "  return;\n"
+               "case 8:\n"
+               "  x = 8; // comment\n"
+               "  break;\n"
                "default: y = 1; break;\n"
                "}",
                Style);