[cfe-dev] Looking for some help debugging LambdaBodyIndentation option
Vitali Lovich via cfe-dev
cfe-dev at lists.llvm.org
Wed Sep 15 16:22:47 PDT 2021
Hi, I've observed a few defects in LambdaBodyIndentation. I know I
implemented this but I'm also not familiar with the codebase & I've spent
some time without any forward progress investigating the issues. If anyone
could be so kind as to help me figure out the problem I'd be very grateful.
The issue seems to be related to this logic here in
UnwrappedLineFormatter.cpp line ~831
if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
P.NestedBlockIndent == P.LastSpace) {
This is how the snippet gets formatted if there are return types:
return someFunction(
[]() {
someCode();
return someOtherFunction(
[]() -> {
someMoreCode();
someMoreCode();
},
[] -> {
someErrorHandlingCode();
someErrorHandlingCode();
});
},
[] -> {
someErrorHandlingCode();
someErrorHandlingCode();
});
If I elide the return type on the lambdas I get:
return someFunction(
[]() {
someCode();
return someOtherFunction(
[]() {
someMoreCode();
someMoreCode();
},
[] {
someErrorHandlingCode();
someErrorHandlingCode();
});
},
[] {
someErrorHandlingCode();
someErrorHandlingCode();
});
This is closer but still not quite what I want. The desired formatting
should look like:
return someFunction(
[]() {
someCode();
return someOtherFunction(
[]() {
someMoreCode();
someMoreCode();
},
[] {
someErrorHandlingCode();
someErrorHandlingCode();
});
},
[] {
someErrorHandlingCode();
someErrorHandlingCode();
});
Actually I'd prefer the lambda be inline with the preceding lines if line
width permits but I'm not sure why it seems to always be put on a new line:
return someFunction([]() {
someCode();
return someOtherFunction(
[]() {
someMoreCode();
someMoreCode();
}, [] {
someErrorHandlingCode();
someErrorHandlingCode();
});
}, [] {
someErrorHandlingCode();
someErrorHandlingCode();
});
Probably unrelated to my changes though as stock clang format appears to
put it on a newline & I can't figure out how. In theory setting
BeforeLambdaBody:
false should do it according to the docs but it doesn't seem to.
Thanks for any tips/pointers,
Vitali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210915/c8eb3288/attachment.html>
More information about the cfe-dev
mailing list