[llvm-bugs] [Bug 49352] New: Inconsistent & non-configurable indentation of lambda body
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Feb 25 07:48:34 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49352
Bug ID: 49352
Summary: Inconsistent & non-configurable indentation of lambda
body
Product: clang
Version: 11.0
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Formatter
Assignee: unassignedclangbugs at nondot.org
Reporter: vlovich at gmail.com
CC: djasper at google.com, klimek at google.com,
llvm-bugs at lists.llvm.org
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 @ https://github.com/capnproto/capnproto) 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).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210225/80b60ed9/attachment-0001.html>
More information about the llvm-bugs
mailing list