소스 검색

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 년 전
부모
커밋
f081f81b53
2개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  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.
     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;

+ 4 - 0
unittests/Format/FormatTest.cpp

@@ -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");