[clang] [clang-format] Merge inline short functions for BS_Whitesmiths (PR #134473)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 4 19:35:05 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fix 126747
---
Full diff: https://github.com/llvm/llvm-project/pull/134473.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+7-2)
- (modified) clang/unittests/Format/FormatTest.cpp (+7)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/134473
More information about the cfe-commits
mailing list