]> granicus.if.org Git - clang/commitdiff
clang-format: Understand that breaking before lambdas is fine.
authorDaniel Jasper <djasper@google.com>
Tue, 24 Jun 2014 09:15:49 +0000 (09:15 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 24 Jun 2014 09:15:49 +0000 (09:15 +0000)
Before:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([](
      const aaaaaaaaaa &a) { return a; });

After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      [](const aaaaaaaaaa &a) { return a; });

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

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

index 3793fe056ed2f92d88496d417431809b3df6dd71..0760f35bbbc287c95ecc77fb6e856d02b88bd53f 100644 (file)
@@ -1315,7 +1315,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Right.is(tok::l_square)) {
     if (Style.Language == FormatStyle::LK_Proto)
       return 1;
-    if (Right.Type != TT_ObjCMethodExpr)
+    if (Right.Type != TT_ObjCMethodExpr && Right.Type != TT_LambdaLSquare)
       return 500;
   }
   if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator)) {
index 968e13b3feba30b6869f5390e8d5df6889e0e63b..11a42a51faffb5cdaa72e2a6ca6038c982947efd 100644 (file)
@@ -8721,6 +8721,8 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("void f() {\n"
                "  SomeFunction([](decltype(x), A *a) {});\n"
                "}");
+  verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "    [](const aaaaaaaaaa &a) { return a; });");
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");
@@ -8728,7 +8730,7 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
   verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n"
                "                   int j) -> int {\n"
-               "  return fffffffffffffffffffffffffffffffffffffff(i * j);\n"
+               "  return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n"
                "};");
 
   // Multiple lambdas in the same parentheses change indentation rules.