diff options
author | Owen Pan <owenpiano@gmail.com> | 2025-05-19 01:30:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-19 01:30:42 -0700 |
commit | 6da2acf8e99ec517bfbe498af2519d29834e2583 (patch) | |
tree | 5a45ef3dba0c833cf6230e968cd83059b16198b8 | |
parent | 8231182fed491b25a9597ba83cd284e097cc31ac (diff) | |
download | llvm-6da2acf8e99ec517bfbe498af2519d29834e2583.zip llvm-6da2acf8e99ec517bfbe498af2519d29834e2583.tar.gz llvm-6da2acf8e99ec517bfbe498af2519d29834e2583.tar.bz2 |
[clang-format] Merge short inline function in macro definition body (#140366)
Fix #62356
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 1298e3e..f2ed027 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -314,8 +314,8 @@ private: 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 8fe57c8..c0633ba 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -15093,6 +15093,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; |