[clang-format] Ignore first token when finding MustBreak
authorEmilia Kond <emilia@rymiel.space>
Thu, 18 May 2023 02:50:10 +0000 (05:50 +0300)
committerEmilia Kond <emilia@rymiel.space>
Thu, 18 May 2023 02:50:26 +0000 (05:50 +0300)
commit06763ea5d8f96625545bb2c2445363aca9922bf1
treed3281bb15e2209d534d0f34386d02249db7cfa58
parent2d5ef39184a4f17d75b0cd640f442cc43fe7edfc
[clang-format] Ignore first token when finding MustBreak

When in ColumnLimit 0, the formatter looks for MustBreakBefore in the
line in order to check if a line is allowed to be merged onto one line.

However, since MustBreakBefore is really a property of the gap between
the token and the one previously, I belive the check is erroneous in
checking all the tokens in a line, since whether the previous line ended
with a forced line break should have no effect on whether the current
line is allowed to merge with the next one.

This patch changes the check to skip the first token in
`LineJoiner.containsMustBreak`.

This patch also changes a test, which is not ideal, but I believe the
test also suffered from this bug. The test case in question sets
AllowShortFunctionsOnASingleLine to "Empty", but the empty function in
said test case isn't merged to a single line, because of the very same
bug this patch fixes.

Fixes https://github.com/llvm/llvm-project/issues/62721

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D150614
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp