]> granicus.if.org Git - clang/commitdiff
clang-format: Handle comments in short case labels.
authorDaniel Jasper <djasper@google.com>
Fri, 21 Nov 2014 12:36:25 +0000 (12:36 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 21 Nov 2014 12:36:25 +0000 (12:36 +0000)
With AllowShortCaseLabelsOnASingleLine set to true:
This gets now left unchanged:
  case 1:
    // comment
    return;

Whereas before it was changed into:
  case 1: // comment return;

This fixes llvm.org/PR21630.

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

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

index 729ca97aabe7b8d556f24aea16a72a8c32684504..b96c17abbc0e8dd82769cb83c01891a5e22c19f8 100644 (file)
@@ -750,7 +750,7 @@ 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::kw_while, tok::comment))
         return 0;
       Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
     }
index a6bbe16d8639aebf433e25d9f24c3090bd36ce35..c58ac0a8f9e61342053e13d5f000b920d1e754a3 100644 (file)
@@ -745,6 +745,11 @@ TEST_F(FormatTest, ShortCaseLabels) {
                "case 3:\n"
                "case 4:\n"
                "case 5: return;\n"
+               "case 6: // comment\n"
+               "  return;\n"
+               "case 7:\n"
+               "  // comment\n"
+               "  return;\n"
                "default: y = 1; break;\n"
                "}",
                Style);