]> granicus.if.org Git - clang/commitdiff
clang-format: Prefer not to put lambdas on a single line.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Aug 2014 12:00:13 +0000 (12:00 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Aug 2014 12:00:13 +0000 (12:00 +0000)
Before:
  string abc =
      SomeFunction(aaaaaaaaaaaaa, aaaaa,
                   []() { SomeOtherFunctioooooooooooooooooooooooooon(); });

After:
  string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {
    SomeOtherFunctioooooooooooooooooooooooooon();
  });

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

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

index 54644ad768ec9b7d2876890193268de597daf76d..f817224e195b8892b605b869a283bd2370214531 100644 (file)
@@ -1420,6 +1420,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
     return 100;
   if (Left.is(tok::equal) && InFunctionDecl)
     return 110;
+  if (Right.is(tok::r_brace))
+    return 1;
   if (Left.opensScope())
     return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter
                                    : 19;
index bd55c9ef2192cd695bc583ff9edab2145c94de49..a171066fa37153e1e1f245948608c4e40456b10f 100644 (file)
@@ -8819,6 +8819,9 @@ TEST_F(FormatTest, FormatsLambdas) {
                "}");
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
                "    [](const aaaaaaaaaa &a) { return a; });");
+  verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n"
+               "  SomeOtherFunctioooooooooooooooooooooooooon();\n"
+               "});");
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");