[clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine...
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Thu, 3 Mar 2022 14:37:43 +0000 (15:37 +0100)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Mon, 7 Mar 2022 15:54:08 +0000 (16:54 +0100)
commitd03e342803df7a75fb86c5a5c07cd84f3683bef9
treeda09ad377db0623c573855e1a125823a2f48c167
parent27fe8605a82f5c1fe8196e352ba00a7776516afb
[clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

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

When handling `AllowShortFunctionsOnASingleLine`, we were searching for the last line with a smaller level than the current line. The search was incorrect when the first line had the same level as the current one. This led to an unsatisfied assumption about the existence of a brace (non-comment token).

Reviewed By: HazardyKnusperkeks, owenpan

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