]> granicus.if.org Git - clang/commitdiff
clang-format: Don't indent lambda body relative to its return type.
authorDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 07:48:45 +0000 (07:48 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 07:48:45 +0000 (07:48 +0000)
Before:
  []()  //
      -> int {
        return 1;  //
      };

After:
  []()  //
      -> int {
    return 1;  //
  };

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

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

index 7f88eea4060a0fdbcc0f2560d8156e6b3bf62576..322969e4bb71edc7be9724deec57ebd77ee10e49 100644 (file)
@@ -476,11 +476,13 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
   //     // code
   //   }
   //
-  // is common and should be formatted like a free-standing function.
-  if (Style.Language != FormatStyle::LK_JavaScript ||
-      Current.NestingLevel != 0 || !PreviousNonComment ||
-      !PreviousNonComment->is(tok::equal) ||
-      !Current.isOneOf(Keywords.kw_async, Keywords.kw_function))
+  // is common and should be formatted like a free-standing function. The same
+  // goes for wrapping before the lambda return type arrow.
+  if (!Current.is(TT_LambdaArrow) &&
+      (Style.Language != FormatStyle::LK_JavaScript ||
+       Current.NestingLevel != 0 || !PreviousNonComment ||
+       !PreviousNonComment->is(tok::equal) ||
+       !Current.isOneOf(Keywords.kw_async, Keywords.kw_function)))
     State.Stack.back().NestedBlockIndent = State.Column;
 
   if (NextNonComment->isMemberAccess()) {
index be24066b20cab8fb8d5f82b195c2651c8b76d62c..d27da34d3406e61c081db3b9c599e5a054f1d790 100644 (file)
@@ -10997,6 +10997,10 @@ TEST_F(FormatTest, FormatsLambdas) {
       "      return aaaaaaaaaaaaaaaaa;\n"
       "    });",
       getLLVMStyleWithColumns(70));
+  verifyFormat("[]() //\n"
+               "    -> int {\n"
+               "  return 1; //\n"
+               "};");
 
   // Multiple lambdas in the same parentheses change indentation rules.
   verifyFormat("SomeFunction(\n"