Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clang/lib/Format/UnwrappedLineFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,13 @@ class LineJoiner {
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;
}
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading