]> granicus.if.org Git - clang/commitdiff
clang-format: Don't indent builders relative to "return".
authorDaniel Jasper <djasper@google.com>
Fri, 30 Aug 2013 07:27:13 +0000 (07:27 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 30 Aug 2013 07:27:13 +0000 (07:27 +0000)
While this looks kind of nice, it wastes horizontal space and does not
seem to be common in the LLVM codebase.

Before:
  return llvm::StringSwitch<Reference::Kind>(name)
      .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
      .StartsWith(".eh_frame", ORDER_EH_FRAME)
      .StartsWith(".init", ORDER_INIT)
      .StartsWith(".fini", ORDER_FINI)
      .StartsWith(".hash", ORDER_HASH)
      .Default(ORDER_TEXT);

After:
  return llvm::StringSwitch<Reference::Kind>(name)
             .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
             .StartsWith(".eh_frame", ORDER_EH_FRAME)
             .StartsWith(".init", ORDER_INIT)
             .StartsWith(".fini", ORDER_FINI)
             .StartsWith(".hash", ORDER_HASH)
             .Default(ORDER_TEXT);

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

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

index 10295197240d104ee066d8176238c8d1fdc7226c..2737b8d5269d6db08554dea27479ea6eb1b962e9 100644 (file)
@@ -460,7 +460,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
   }
 
   // If return returns a binary expression, align after it.
-  if (Current.is(tok::kw_return) && !Current.FakeLParens.empty())
+  if (Current.is(tok::kw_return) && startsBinaryExpression(Current))
     State.Stack.back().LastSpace = State.Column + 7;
 
   // In ObjC method declaration we align on the ":" of parameters, but we need
index eee888893032b1b458f01374be838f866ad4a03c..dc2dc01e2034749c18f2e0e6642c5f73a46fa559 100644 (file)
@@ -2841,12 +2841,12 @@ TEST_F(FormatTest, AdaptiveOnePerLineFormatting) {
 TEST_F(FormatTest, FormatsBuilderPattern) {
   verifyFormat(
       "return llvm::StringSwitch<Reference::Kind>(name)\n"
-      "           .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
-      "           .StartsWith(\".eh_frame\", ORDER_EH_FRAME)\n"
-      "           .StartsWith(\".init\", ORDER_INIT)\n"
-      "           .StartsWith(\".fini\", ORDER_FINI)\n"
-      "           .StartsWith(\".hash\", ORDER_HASH)\n"
-      "           .Default(ORDER_TEXT);\n");
+      "    .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
+      "    .StartsWith(\".eh_frame\", ORDER_EH_FRAME)\n"
+      "    .StartsWith(\".init\", ORDER_INIT)\n"
+      "    .StartsWith(\".fini\", ORDER_FINI)\n"
+      "    .StartsWith(\".hash\", ORDER_HASH)\n"
+      "    .Default(ORDER_TEXT);\n");
 
   verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
                "       aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");