[cfe-dev] Looking for some help debugging LambdaBodyIndentation option

Vitali Lovich via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 15 16:26:02 PDT 2021


It looks like the formatting for my e-mail may have been stripped. If
that's the case it should be possible to copy-paste the different lambdas
into clang-format with --style='{LambdaBodyIndentation: OuterScope}'.

The last lambda of what I'm trying to get to can be found here:
https://pastebin.com/eSGJnubw


On Wed, Sep 15, 2021 at 4:22 PM Vitali Lovich <vlovich at gmail.com> wrote:

> 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/211ce261/attachment-0001.html>


More information about the cfe-dev mailing list