[llvm-bugs] [Bug 49353] New: Options to control how lambda capture group/arguments are reflowed

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 25 08:05:12 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49353

            Bug ID: 49353
           Summary: Options to control how lambda capture group/arguments
                    are reflowed
           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

Currently clang-format doesn't expose any knobs to tune the formatting of
lambdas. For the KJ style guide
(https://github.com/capnproto/capnproto/blob/master/style-guide.md) the
following knobs would be ideal:

1. A knob to force the capture group + argument list for a lambda to go on a
new line if the capture group + argument list cannot fit on 1 line. Currently
clang-format will some times put it on a new line but other times will align to
the previous line.
2. A knob to force argument lists onto a separate line from the capture group
if the capture group + argument list doesn't fit on 1 line.


It should be possible to take any version of this (i.e. any length of capture
group/argument list):

callSomething([someArgument, someOtherArgument](int arg1, int arg2) {
  // code
});

and always format it as:

callSomething(
    [someArgument, someOtherArgument]
    (int arg1, int arg2) {
  // code (this indentation of the body isn't actually always guaranteed today
- https://bugs.llvm.org/show_bug.cgi?id=49352 for an enhancement there)
});

if the capture group + argument list need reflowing.

If there needs to be a reflow but the capture group + argument list can stay on
one line the expected output would be:

callSomething(
    [someArgument, someOtherArgument](int arg1, int arg2) {
  // code (this indentation of the body isn't actually always guaranteed today
- https://bugs.llvm.org/show_bug.cgi?id=49352 for an enhancement there)
});

So the two options (using terrible names) to control this behavior might look
like:

LambdaArgumentListOnNewlineIfNotSingleLine: bool
CaptureGroupOnNewlineIfLambdaHeaderNotSingleLine: bool

-- 
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/ae5b5d0b/attachment.html>


More information about the llvm-bugs mailing list