Open dd39fb77-d703-45fe-9da2-cbf576d010cd opened 3 years ago
I think both examples you present are correct. However the bug reported here is something else.
The bug happens when you format the file, then you format the first line only on the already formatted file, e.g. "clang-format -lines 1:1", or when you use git clang-format after modifying the first line.
I have attached an archive which has a .clang-format file and a test.c file to reproduce the issue. Run "clang-format test.c", and test.c will be output with no changes:
int b(void);
int u(int, int);
bool g(void);
Now run "clang-format --lines 1:1 test.c" and you will see:
int b(void);
int u(int, int);
bool g(void);
I hope we can agree that this is not desired behaviour.
Is this really a bug? or is your column limit just turning off the alignment for the longer line: i.e.
int u(int, int);
will be formatted as
int u(int, int);
which is 17 characters not 16
For me ColumnLimit = 16 formats as
int b(void); int u(int, int); bool g(void);
ColummLimit = 17 as
int b(void); int u(int, int); bool g(void);
Both of which seem correct to me, can you confirm
Extended Description
Test case is as follows (add to clang/unittests/Format/FormatTestSelective.cpp):
Test result:
Expected result: There are no changes when reformatting the first line.
Another thing to note is that u is not aligned to g. It could be, if the parameters were moved to the next line. This is what happens when u is changed to uu, making that line longer than the ColumnLimit.
The bug is present on the main branch at commit 8e6fc1f97eb9a63780158470596ddbec3d0ecd59