[clang-format] Merge inline short functions for BS_Whitesmiths (#134473)

Fix #126747
This commit is contained in:
Owen Pan 2025-04-05 17:03:55 -07:00 committed by GitHub
parent 55ff96abfa
commit aaaeb86ace
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -316,8 +316,13 @@ private:
const AnnotatedLine *Line = nullptr;
for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) {
assert(*J);
if (!(*J)->InPPDirective && !(*J)->isComment() &&
(*J)->Level < TheLine->Level) {
if ((*J)->InPPDirective || (*J)->isComment() ||
(*J)->Level > TheLine->Level) {
continue;
}
if ((*J)->Level < TheLine->Level ||
(Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths &&
(*J)->First->is(tok::l_brace))) {
Line = *J;
break;
}

View File

@ -15142,6 +15142,13 @@ TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) {
"}",
MergeInlineOnly);
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
verifyFormat("class Foo\n"
" {\n"
" void f() { foo(); }\n"
" };",
MergeInlineOnly);
// Also verify behavior when BraceWrapping.AfterFunction = true
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
MergeInlineOnly.BraceWrapping.AfterFunction = true;