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;