================
@@ -325,13 +325,30 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
   if (Current.isMemberAccess() && CurrentState.ContainsUnwrappedBuilder)
     return false;
 
-  // Don't create a 'hanging' indent if there are multiple blocks in a single
-  // statement and we are aligning lambda blocks to their signatures.
-  if (Previous.is(tok::l_brace) && State.Stack.size() > 1 &&
+  // Force a lambda onto a new line so that we don't create a 'hanging' indent
+  // if there are multiple blocks in a single statement and we are aligning
+  // lambda blocks to their signatures.
+  if (Previous.is(tok::l_brace) && State.Stack.size() > 2 &&
       State.Stack[State.Stack.size() - 2].NestedBlockInlined &&
       State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks &&
       Style.LambdaBodyIndentation == FormatStyle::LBI_Signature) {
-    return false;
+    if (!Style.isCpp())
+      return false;
+
+    // Make sure to push lambdas to a new line when they are an argument with
+    // other arguments preceding them.
+    if (State.Stack[State.Stack.size() - 2].StartOfFunctionCall > 0)
+      return false;
+
+    // Only force a new line if it is not just going to create a worse hanging
+    // indent. Otherwise, based on the ContinuationIndentWidth, we could end up
+    // more indented than we would've been. To avoid odd looking breaks, make
+    // sure we save at least IndentWidth.
+    if (State.Stack[State.Stack.size() - 3].Indent +
+            Style.ContinuationIndentWidth + Style.IndentWidth <
+        State.Stack[State.Stack.size() - 2].Indent) {
----------------
owenca wrote:

```suggestion
    if (State.Stack.size() > 2 &&
+        State.Stack[State.Stack.size() - 3].Indent +
+                Style.ContinuationIndentWidth + Style.IndentWidth <
+            State.Stack[State.Stack.size() - 2].Indent) {
```

https://github.com/llvm/llvm-project/pull/141576
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to