From ea40cee24d8b7aed0ded49c3bab0d5a9791b886b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 14 Jul 2015 11:26:14 +0000 Subject: [PATCH] clang-format: Fix formatting of multiple lambdas in initializers. Before: SomeFunction({[&] { // comment }, [&] { // comment }}); After: SomeFunction({[&] { // comment }, [&] { // comment }}); llvm-svn: 242138 --- clang/lib/Format/ContinuationIndenter.cpp | 6 ++++-- clang/unittests/Format/FormatTest.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index c3f069b..dd56831 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -862,6 +862,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, unsigned LastSpace = State.Stack.back().LastSpace; bool AvoidBinPacking; bool BreakBeforeParameter = false; + unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall, + State.Stack.back().NestedBlockIndent); if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) { if (Current.opensBlockTypeList(Style)) { NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth; @@ -875,6 +877,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, Current.isOneOf(TT_ArrayInitializerLSquare, TT_DictLiteral) || Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments || (NextNoComment && NextNoComment->is(TT_DesignatedInitializerPeriod)); + if (Current.ParameterCount > 1) + NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1); } else { NewIndent = Style.ContinuationIndentWidth + std::max(State.Stack.back().LastSpace, @@ -922,8 +926,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, bool NoLineBreak = State.Stack.back().NoLineBreak || (Current.is(TT_TemplateOpener) && State.Stack.back().ContainsUnwrappedBuilder); - unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall, - State.Stack.back().NestedBlockIndent); State.Stack.push_back(ParenState(NewIndent, NewIndentLevel, LastSpace, AvoidBinPacking, NoLineBreak)); State.Stack.back().NestedBlockIndent = NestedBlockIndent; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6aa7681..d61dc7f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9866,6 +9866,15 @@ TEST_F(FormatTest, FormatsLambdas) { " return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa;\n" "});", getLLVMStyleWithColumns(60)); + verifyFormat("SomeFunction({[&] {\n" + " // comment\n" + " },\n" + " [&] {\n" + " // comment\n" + " }});"); + verifyFormat("SomeFunction({[&] {\n" + " // comment\n" + "}});"); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n"); -- 2.7.4