[llvm-bugs] [Bug 50860] New: FR: An option to continue binpack after a multiline string literal break

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 24 23:52:53 PDT 2021


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

            Bug ID: 50860
           Summary: FR: An option to continue binpack after a multiline
                    string literal break
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kkm at pobox.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Currently, clang-format is unconditionally breaking the argument list after
splitting a C/C++ string into multiple lines. The justification for this
behavior is given near the very end of
ContinuationIndenter::breakProtrudingToken() in
clang/lib/Format/ContinuationIndenter.cpp (see
https://github.com/llvm/llvm-project/blob/d480f968a/clang/lib/Format/ContinuationIndenter.cpp#L2341-L2354):

    // If we break the token inside a parameter list, we need to break before
    // the next parameter on all levels, so that the next parameter is clearly
    // visible. Line comments already introduce a break.

While it's generally a good idea, at times it leads to quite an ugly line
breaks, like this example

    fmt::print("The answer to life, the universe, and everything is "
               "{}",
               n);

While, of course, this particular example may be best formatted without
splitting the string at all and breaking the line after the opening '('
instead, this is just an example. Sometimes long log messages require breaking
into more than 2 lines (we use Google style and the hard limit of 80
characters), and are followed by just one short argument. Another soft
objection to this design decision is that nearly any modern text editor in fact
used for writing code (nano and notepad thus excluded) highlights language
syntax, so that the next argument is "clearly visible" even without a line
break: most default color schemes highlight string constants so that they stand
out well enough.

There are just too many cases in our codebase that carry over just one short
parameter to the next line, and the current unconditional behavior is not
really of much help to code readability. It may be argued that this particular
case is rather detrimental to it: both '"{},"' and 'n);' are "clearly visible",
in the above justification's sense, but the apparent intent is to make "clearly
visible" only the latter.

I propose a single Boolean option, for example,
'BreakBinPackAfterMultilineString', with the current behavior set by 'true';
'false' would not force this line break.

I can write implementation for the option; I'm opening this issue primarily to
discuss the proposal.

-- 
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/20210625/135af56a/attachment.html>


More information about the llvm-bugs mailing list