<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Inconsistent & non-configurable indentation of lambda body"
   href="https://bugs.llvm.org/show_bug.cgi?id=49352">49352</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inconsistent & non-configurable indentation of lambda body
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Formatter
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vlovich@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Some times the lambda body is indented relative to outer scope and other times
it's indented relative to the lambda depending on where the line break for the
capture group is. It would be nice to be able to specify a way to have this be
consistently chosen (something like LambdaBodyRelativeTo: [Default,
AlwaysParent]). The KJ library in the examples being used is the one from
Cap'n'Proto @ <a href="https://github.com/capnproto/capnproto">https://github.com/capnproto/capnproto</a>) although that shouldn't
matter. The code references variables that don't exist just to pad out the
length of the line as needed.

Raw:
----
% cat test1.cpp
kj::Promise<void> SomeClass::doSomething(kj::Promise<kj::Array<int>> promise) {
  return promise.then([this, &someVariable, someObject =
kj::mv(s)](kj::Array<int> evaluated) mutable {
    return someObject.startAsyncAction().then([this,
&someVariable](AsyncActionResult result) mutable {
      result.processMore();
    });
  });
}

Formatted
------
% clang-format --style=file test1.cpp
kj::Promise<void> SomeClass::doSomething(kj::Promise<kj::Array<int>> promise) {
  return promise.then(
      [this, &someVariable, someObject = kj::mv(s)](kj::Array<int> evaluated)
mutable {
        return someObject.startAsyncAction().then(
            [this, &someVariable](AsyncActionResult result) mutable {
result.processMore(); });
      });
}

Changing it slightly.

Raw
----
% cat test2.cpp
kj::Promise<void> SomeClass::doSomething(kj::Promise<kj::Array<int>> promise) {
  return promise.then([this, &someVariable, someObject = kj::mv(s),
moreVariable1, moreVariable1](kj::Array<int> evaluated) mutable {
    return someObject.startAsyncAction().then([this,
&someVariable](AsyncActionResult result) mutable {
      result.processMore();
    });
  });
}

Formatted:
----
% clang-format --style=file test2.cpp
kj::Promise<void> SomeClass::doSomething(kj::Promise<kj::Array<int>> promise) {
  return promise.then([this, &someVariable, someObject = kj::mv(s),
moreVariable1,
                       moreVariable1](kj::Array<int> evaluated) mutable {
    return someObject.startAsyncAction().then(
        [this, &someVariable](AsyncActionResult result) mutable {
result.processMore(); });
  });
}

Actual:
The formatting between test1.cpp & test2.cpp varies the indentation used for
the lambda body widely based on whether the capture group is part of the parent
line or it's own line.

Desired:
An option to control using the default behavior or always choosing to indent
the body once relative to the parent scope the lambda is in. This has 2
benefits. It's easier to read heavy usage of promise callbacks in C++ code. It
keeps the formatting consistent & minimizes superfluous reflows that occur due
to trivial changes, making diffs smaller & easier to review in editors that
don't have a "hide whitespace option" (or if the user wants to see whitespace
changes & this just generates visual noise).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>