[clang] aaaeb86 - [clang-format] Merge inline short functions for BS_Whitesmiths (#134473)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 5 17:03:58 PDT 2025
Author: Owen Pan
Date: 2025-04-05T17:03:55-07:00
New Revision: aaaeb86acea77c5bcdb60011ce6aaaf4ebca4081
URL: https://github.com/llvm/llvm-project/commit/aaaeb86acea77c5bcdb60011ce6aaaf4ebca4081
DIFF: https://github.com/llvm/llvm-project/commit/aaaeb86acea77c5bcdb60011ce6aaaf4ebca4081.diff
LOG: [clang-format] Merge inline short functions for BS_Whitesmiths (#134473)
Fix #126747
Added:
Modified:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 000a5105ca407..62759d7945f7b 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -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;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4dfa135120605..69c9ee1d1dcb2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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;
More information about the cfe-commits
mailing list