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

Daniel Jasper djasper at google.com
Mon Jan 12 02:23:24 PST 2015


Author: djasper
Date: Mon Jan 12 04:23:24 2015
New Revision: 225625

URL: http://llvm.org/viewvc/llvm-project?rev=225625&view=rev
Log:
clang-format: Improve format of lambdas in ctor initializers.

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

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

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=225625&r1=225624&r2=225625&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jan 12 04:23:24 2015
@@ -632,6 +632,7 @@ unsigned ContinuationIndenter::moveState
     //       ^ 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;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=225625&r1=225624&r2=225625&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 12 04:23:24 2015
@@ -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");





More information about the cfe-commits mailing list