[llvm-bugs] [Bug 31115] New: Braced-init-list misformatted with AlignAfterOpenBracket=AlwaysBreak

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 22 09:21:04 PST 2016


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

            Bug ID: 31115
           Summary: Braced-init-list misformatted with
                    AlignAfterOpenBracket=AlwaysBreak
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: griwes at griwes.info
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 17633
  --> https://llvm.org/bugs/attachment.cgi?id=17633&action=edit
an example

It seems that AlwaysBreak is disregarded for braced-init-lists, and instead
Align is used when either Align or AlwaysBreak are specified for
AlignAfterOpenBracket.

An example is attached. The config I'm using to run clang-format (reduced to
the necessary options) is:

    -style='{BasedOnStyle: WebKit, AlignAfterOpenBracket: AlwaysBreak,
ColumnLimit: 80, BinPackArguments: false, Cpp11BracedListStyle: true}'

(Cpp11BracedListStyle doesn't matter; the only thing it changes is that with
it, the BinPackArguments option is respected. It'd be nice if it was possible
to respect it *without* removing the spaces from within the braces, but that's
not important here.)

The second line in main() in the example yields the expected result:

    std::vector<int> foo(
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname,
        verylongname);

(This is obviously invalid code, but it illustrates the point.) The first line,
however, completely disregards AlignAfterOpenBracket=AlwaysBreak:

    std::vector<int> foo{verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname,
                         verylongname};

while the expected result is the same as for the second line, only with braces
instead of parentheses.

It wouldn't be *very* bad if not for some of my test files that construct
literals corresponding to an AST parsed by the tested code, which causes it to
be completely unreadable with Align. I *could* (and I guess I'll have to, for
now) run two configs, one for the tests that disables this and one for normal
code where this bug doesn't hurt readability that much (but does hurt it
nevertheless), but it's not very nice.

-- 
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/20161122/7ce385ad/attachment-0001.html>


More information about the llvm-bugs mailing list