[llvm-bugs] [Bug 49125] New: clang-format assignment with bitwise operators: Keep line breaks if necessary

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 10 06:16:31 PST 2021


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

            Bug ID: 49125
           Summary: clang-format assignment with bitwise operators: Keep
                    line breaks if necessary
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andi.schulz at me.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

There is currently no way of keeping a multi line assignment with bitwise
operators the way it is. It would be nice if clang-format could allow an option
to recognize unnecessary "merging" when there is an bitwise operator.

.clang-format file:
BasedOnStyle: LLVM
ColumnLimit: 80



Example input:



// This needs no formatting and will be kept this way
int i1 = 10000 | 10001 | 10002 | 10003 | 10004 | 10005 | 10006 | 10007 | 10008;

// This exceeds the ColumnLimit: 80 and will get formatted
int k1 = 10000 | 10001 | 10002 | 10003 | 10004 | 10005 | 10006 | 10007 | 10008
| 10009;

// This is manually formatted, but clang-format will force it into two lines
int m1 = 10000 |
         10001 |
         10002 |
         10003 |
         10004 |
         10005 |
         10006 |
         10007 |
         10008 |
         10009;

// This needs no formatting and will be kept this way
int i2 = get_int() | get_int() | get_int() | get_int() | get_int() | get_int();

// This exceeds the ColumnLimit: 80 and will get formatted
int k2 = get_int() | get_int() | get_int() | get_int() | get_int() | get_int()
| get_int();

// This is manually formatted, but clang-format will force it into two lines
int m2 = get_int() |
         get_int() |
         get_int() |
         get_int() |
         get_int() |
         get_int() |
         get_int();



Example output:



// This needs no formatting and will be kept this way
int i1 = 10000 | 10001 | 10002 | 10003 | 10004 | 10005 | 10006 | 10007 | 10008;

// This exceeds the ColumnLimit: 80 and will get formatted
int k1 = 10000 | 10001 | 10002 | 10003 | 10004 | 10005 | 10006 | 10007 | 10008
|
         10009;

// This is manually formatted, but clang-format will force it into two lines
int m1 = 10000 | 10001 | 10002 | 10003 | 10004 | 10005 | 10006 | 10007 | 10008
|
         10009;

// This needs no formatting and will be kept this way
int i2 = get_int() | get_int() | get_int() | get_int() | get_int() | get_int();

// This exceeds the ColumnLimit: 80 and will get formatted
int k2 = get_int() | get_int() | get_int() | get_int() | get_int() | get_int()
|
         get_int();

// This is manually formatted, but clang-format will force it into two lines
int m2 = get_int() | get_int() | get_int() | get_int() | get_int() | get_int()
|
         get_int();

-- 
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/20210210/39b20647/attachment-0001.html>


More information about the llvm-bugs mailing list