]> granicus.if.org Git - clang/commitdiff
clang-format: Support case ranges.
authorDaniel Jasper <djasper@google.com>
Sun, 20 Oct 2013 16:56:16 +0000 (16:56 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 20 Oct 2013 16:56:16 +0000 (16:56 +0000)
Before (note the missing space before "..." which can lead to compile
errors):
  switch (x) {
    case 'A'... 'Z':
    case 1... 5:
        break;
  }

After:
  switch (x) {
    case 'A' ... 'Z':
    case 1 ... 5:
        break;
  }

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

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

index 9bc109787ae2b2f92ce137d1684fe42ee2c69364..7e794a3d2d546f1c47d3b236563852837033216e 100644 (file)
@@ -1237,7 +1237,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
     return false;
   if (Right.is(tok::ellipsis))
-    return false;
+    return Left.Tok.isLiteral();
   if (Left.is(tok::l_square) && Right.is(tok::amp))
     return false;
   if (Right.Type == TT_PointerOrReference)
index dcb708e0d78f2482a40662ea6356800893953fd8..ad1cf75392b8a06bf1e223a51ce078e55ce497e9 100644 (file)
@@ -590,6 +590,14 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
                "});");
 }
 
+TEST_F(FormatTest, CaseRanges) {
+  verifyFormat("switch (x) {\n"
+               "case 'A' ... 'Z':\n"
+               "case 1 ... 5:\n"
+               "  break;\n"
+               "}");
+}
+
 TEST_F(FormatTest, FormatsLabels) {
   verifyFormat("void f() {\n"
                "  some_code();\n"