[clang] [clang-format] Merge short inline function in macro definition body (PR #140366)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 17 02:43:51 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fix #<!-- -->62356
---
Full diff: https://github.com/llvm/llvm-project/pull/140366.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+2-2)
- (modified) clang/unittests/Format/FormatTest.cpp (+7)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 1298e3e7bab38..f2ed027b2c047 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -314,8 +314,8 @@ 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)->InMacroBody) ||
+ (*J)->isComment() || (*J)->Level > TheLine->Level) {
continue;
}
if ((*J)->Level < TheLine->Level ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 436beaf68bd2a..4116173b47b51 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15086,6 +15086,13 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) {
"};",
MergeInlineOnly);
+ MergeInlineOnly.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+ verifyFormat("#define Foo \\\n"
+ " struct S { \\\n"
+ " void foo() { return; } \\\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/140366
More information about the cfe-commits
mailing list