@@ -329,9 +329,9 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
329329 // statement and we are aligning lambda blocks to their signatures.
330330 if (Previous.is (tok::l_brace) && State.Stack .size () > 1 &&
331331 State.Stack [State.Stack .size () - 2 ].NestedBlockInlined &&
332- State.Stack [State.Stack .size () - 2 ].HasMultipleNestedBlocks &&
333- Style.LambdaBodyIndentation == FormatStyle::LBI_Signature) {
334- return false ;
332+ State.Stack [State.Stack .size () - 2 ].HasMultipleNestedBlocks ) {
333+ return Style.isCpp () &&
334+ Style. LambdaBodyIndentation == FormatStyle::LBI_OuterScope ;
335335 }
336336
337337 // Don't break after very short return types (e.g. "void") as that is often
@@ -706,42 +706,48 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
706706 const FormatToken &Previous = *State.NextToken ->Previous ;
707707 auto &CurrentState = State.Stack .back ();
708708
709- bool DisallowLineBreaksOnThisLine =
710- Style.LambdaBodyIndentation == FormatStyle::LBI_Signature &&
711- // Deal with lambda arguments in C++. The aim here is to ensure that we
712- // don't over-indent lambda function bodies when lambdas are passed as
713- // arguments to function calls. We do this by ensuring that either all
714- // arguments (including any lambdas) go on the same line as the function
715- // call, or we break before the first argument.
716- Style.isCpp () && [&] {
717- // For example, `/*Newline=*/false`.
718- if (Previous.is (TT_BlockComment) && Current.SpacesRequiredBefore == 0 )
719- return false ;
720- const auto *PrevNonComment = Current.getPreviousNonComment ();
721- if (!PrevNonComment || PrevNonComment->isNot (tok::l_paren))
722- return false ;
723- if (Current.isOneOf (tok::comment, tok::l_paren, TT_LambdaLSquare))
724- return false ;
725- auto BlockParameterCount = PrevNonComment->BlockParameterCount ;
726- if (BlockParameterCount == 0 )
727- return false ;
709+ // Deal with lambda arguments in C++. The aim here is to ensure that we don't
710+ // over-indent lambda function bodies when lambdas are passed as arguments to
711+ // function calls. We do this by ensuring that either all arguments (including
712+ // any lambdas) go on the same line as the function call, or we break before
713+ // the first argument.
714+ auto DisallowLineBreaks = [&] {
715+ if (!Style.isCpp () ||
716+ Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope) {
717+ return false ;
718+ }
728719
729- // Multiple lambdas in the same function call .
730- if (BlockParameterCount > 1 )
731- return true ;
720+ // For example, `/*Newline=*/false` .
721+ if (Previous. is (TT_BlockComment) && Current. SpacesRequiredBefore == 0 )
722+ return false ;
732723
733- // A lambda followed by another arg.
734- if (!PrevNonComment->Role )
735- return false ;
736- auto Comma = PrevNonComment->Role ->lastComma ();
737- if (!Comma)
738- return false ;
739- auto Next = Comma->getNextNonComment ();
740- return Next &&
741- !Next->isOneOf (TT_LambdaLSquare, tok::l_brace, tok::caret);
742- }();
724+ if (Current.isOneOf (tok::comment, tok::l_paren, TT_LambdaLSquare))
725+ return false ;
726+
727+ const auto *Prev = Current.getPreviousNonComment ();
728+ if (!Prev || Prev->isNot (tok::l_paren))
729+ return false ;
730+
731+ if (Prev->BlockParameterCount == 0 )
732+ return false ;
733+
734+ // Multiple lambdas in the same function call.
735+ if (Prev->BlockParameterCount > 1 )
736+ return true ;
737+
738+ // A lambda followed by another arg.
739+ if (!Prev->Role )
740+ return false ;
741+
742+ const auto *Comma = Prev->Role ->lastComma ();
743+ if (!Comma)
744+ return false ;
745+
746+ const auto *Next = Comma->getNextNonComment ();
747+ return Next && !Next->isOneOf (TT_LambdaLSquare, tok::l_brace, tok::caret);
748+ };
743749
744- if (DisallowLineBreaksOnThisLine )
750+ if (DisallowLineBreaks () )
745751 State.NoLineBreak = true ;
746752
747753 if (Current.is (tok::equal) &&
0 commit comments