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

            Bug ID: 45388
           Summary: Clang Format AlignConsecutiveAssignments breaks based
                    on line length and/or identifier length
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

Created attachment 23304
  --> https://bugs.llvm.org/attachment.cgi?id=23304&action=edit
Clang format options used to recreate this issue

I found I have to run clang-format more than once sometimes for some reason. 
It appears that clang-format will inject a formatting error (probably because
it's confused about column alignment with adjoining lines) which is then
corrected by running a second time.

I was able to recreate the issue on the following snippet.

void Blah() {
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIFIER_NAME_HERE = (4 * 1024);
//My comment of a specific size 12345678901
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIF              = (4 * 1024);
// My comment of a specific size 12345678901
}

It seems that clang-format will unindent the second constant's assignment,
which then gets resolved if I re-run the formatter a second time. Here's the
output I get after I run clang-format the first time:

void Blah() {
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIFIER_NAME_HERE = (4 * 1024);
// My comment of a specific size 12345678901
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIF = (4 * 1024); // My comment
of a specific size 12345678901
}

Then if I run it a second time I get the desired output below:

void Blah() {
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIFIER_NAME_HERE = (4 * 1024);
// My comment of a specific size 12345678901
    const uint32_t MY_REALLY_LONG_CONSTANT_IDENTIF              = (4 * 1024);
// My comment of a specific size 12345678901
}

Interestingly, this seems specific to the total line length of the first
constant (the line with the formatting error in the comment) and the constant
identifier length for the second constant. If I shorten either the comment of
the first constant or the name of the second constant at all the formatter
works properly the on the first run and no second run is necessary.

As far as I can tell, the line is still well within the column limit of 150
specified in the options, so I'm not sure why this is happening.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to