Skip to content

Commit aaaeb86

Browse files
authored
[clang-format] Merge inline short functions for BS_Whitesmiths (#134473)
Fix #126747
1 parent 55ff96a commit aaaeb86

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,13 @@ class LineJoiner {
316316
const AnnotatedLine *Line = nullptr;
317317
for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) {
318318
assert(*J);
319-
if (!(*J)->InPPDirective && !(*J)->isComment() &&
320-
(*J)->Level < TheLine->Level) {
319+
if ((*J)->InPPDirective || (*J)->isComment() ||
320+
(*J)->Level > TheLine->Level) {
321+
continue;
322+
}
323+
if ((*J)->Level < TheLine->Level ||
324+
(Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths &&
325+
(*J)->First->is(tok::l_brace))) {
321326
Line = *J;
322327
break;
323328
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15142,6 +15142,13 @@ TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) {
1514215142
"}",
1514315143
MergeInlineOnly);
1514415144

15145+
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
15146+
verifyFormat("class Foo\n"
15147+
" {\n"
15148+
" void f() { foo(); }\n"
15149+
" };",
15150+
MergeInlineOnly);
15151+
1514515152
// Also verify behavior when BraceWrapping.AfterFunction = true
1514615153
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
1514715154
MergeInlineOnly.BraceWrapping.AfterFunction = true;

0 commit comments

Comments
 (0)