Bladeren bron

clang-format: Improve format of lambdas in ctor initializers.

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
Daniel Jasper 10 jaren geleden
bovenliggende
commit
f081f81b53
2 gewijzigde bestanden met toevoegingen van 5 en 0 verwijderingen
  1. 1 0
      lib/Format/ContinuationIndenter.cpp
  2. 4 0
      unittests/Format/FormatTest.cpp

+ 1 - 0
lib/Format/ContinuationIndenter.cpp

@@ -632,6 +632,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
     //       ^ line up here.
     //       ^ line up here.
     State.Stack.back().Indent =
     State.Stack.back().Indent =
         State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
         State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
+    State.Stack.back().NestedBlockIndent = State.Stack.back().Indent;
     if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
     if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
       State.Stack.back().AvoidBinPacking = true;
       State.Stack.back().AvoidBinPacking = true;
     State.Stack.back().BreakBeforeParameter = false;
     State.Stack.back().BreakBeforeParameter = false;

+ 4 - 0
unittests/Format/FormatTest.cpp

@@ -9380,6 +9380,10 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n"
   verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n"
                "  SomeOtherFunctioooooooooooooooooooooooooon();\n"
                "  SomeOtherFunctioooooooooooooooooooooooooon();\n"
                "});");
                "});");
+  verifyFormat("Constructor()\n"
+               "    : Field([] { // comment\n"
+               "        int i;\n"
+               "      }) {}");
 
 
   // Lambdas with return types.
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");
   verifyFormat("int c = []() -> int { return 2; }();\n");