]> granicus.if.org Git - clang/commitdiff
clang-format: Improve format of lambdas in ctor initializers.
authorDaniel Jasper <djasper@google.com>
Mon, 12 Jan 2015 10:23:24 +0000 (10:23 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 12 Jan 2015 10:23:24 +0000 (10:23 +0000)
Before:
  Constructor()
      : Constructor([] { // comment
        int i;
      }) {}

After:
  Constructor()
      : Constructor([] { // comment
          int i;
        }) {}

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

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

index f05471e712dd6adb5dbfe1b053641a0d41899149..4cc92b02a9e58f1c096d2be4d48eb7bf08c9659e 100644 (file)
@@ -632,6 +632,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
     //       ^ line up here.
     State.Stack.back().Indent =
         State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
+    State.Stack.back().NestedBlockIndent = State.Stack.back().Indent;
     if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
       State.Stack.back().AvoidBinPacking = true;
     State.Stack.back().BreakBeforeParameter = false;
index a49a35c1defb2cf5bee129e42b889ba7427115e4..3bb55402e715a2951fdf77bfe33fd05171647978 100644 (file)
@@ -9380,6 +9380,10 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n"
                "  SomeOtherFunctioooooooooooooooooooooooooon();\n"
                "});");
+  verifyFormat("Constructor()\n"
+               "    : Field([] { // comment\n"
+               "        int i;\n"
+               "      }) {}");
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");