]> granicus.if.org Git - clang/commitdiff
clang-format: Fix case-indentation in macros.
authorDaniel Jasper <djasper@google.com>
Mon, 2 Sep 2013 08:26:29 +0000 (08:26 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 2 Sep 2013 08:26:29 +0000 (08:26 +0000)
Before:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
    return operations::Operation##name

After:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
      return operations::Operation##name

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

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

index fb63899f4719842ca376edfa4391da56e6d1483b..a149c185aa8a4e02c9df810a0cb5e12685e51867 100644 (file)
@@ -235,8 +235,9 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
       break;
     case tok::kw_default:
     case tok::kw_case:
-      if (!SwitchLabelEncountered)
-        Line->Level += Style.IndentCaseLabels;
+      if (!SwitchLabelEncountered &&
+          (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1)))
+        ++Line->Level;
       SwitchLabelEncountered = true;
       parseStructuralElement();
       break;
@@ -864,8 +865,6 @@ void UnwrappedLineParser::parseDoWhile() {
 }
 
 void UnwrappedLineParser::parseLabel() {
-  if (FormatTok->Tok.isNot(tok::colon))
-    return;
   nextToken();
   unsigned OldLineLevel = Line->Level;
   if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0))
index c30133a4b8ae268ad2c262c7fb910f577ef7ae11..51577a66c7fb9d3ad8dfc6b9e9a68b82dd011f22 100644 (file)
@@ -525,6 +525,10 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
                "  case a:          \\\n"
                "    foo = b;       \\\n"
                "  }", getLLVMStyleWithColumns(20));
+  verifyFormat("#define OPERATION_CASE(name)           \\\n"
+               "  case OP_name:                        \\\n"
+               "    return operations::Operation##name\n",
+               getLLVMStyleWithColumns(40));
 
   verifyGoogleFormat("switch (x) {\n"
                      "  case 1:\n"