]> granicus.if.org Git - clang/commitdiff
clang-format: Prefer wrapping a lambda's body over the lambda's return type.
authorDaniel Jasper <djasper@google.com>
Mon, 2 Mar 2015 10:35:13 +0000 (10:35 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 2 Mar 2015 10:35:13 +0000 (10:35 +0000)
Before:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa)
          -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; });

After:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa {
        return aaaaaaaaaaaaaaaaa;
      });

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

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

index 853a56b6a42e2b40c6c083ba02b1270384067d95..1688568c7b1df43ff96c5ef366425ab7f40777f5 100644 (file)
@@ -1535,6 +1535,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
       return Style.PenaltyReturnTypeOnItsOwnLine;
     return 200;
   }
+  if (Right.is(TT_TrailingReturnArrow))
+    return 110;
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
     return 150;
   if (Left.is(TT_CastRParen))
index e76335621fefefc5c9df398d9f5682933633a925..bfc601fb2035935c3a888620225591905cc18f43 100644 (file)
@@ -9537,6 +9537,12 @@ TEST_F(FormatTest, FormatsLambdas) {
                "                   int j) -> int {\n"
                "  return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n"
                "};");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaaa(\n"
+      "    [](aaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaa {\n"
+      "      return aaaaaaaaaaaaaaaaa;\n"
+      "    });",
+      getLLVMStyleWithColumns(70));
 
   // Multiple lambdas in the same parentheses change indentation rules.
   verifyFormat("SomeFunction(\n"