diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index f2ed027b2c047..ac8c0c8fd0ec0 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -986,8 +986,10 @@ class LineJoiner { void join(AnnotatedLine &A, const AnnotatedLine &B) { assert(!A.Last->Next); assert(!B.First->Previous); - if (B.Affected) + if (B.Affected || B.LeadingEmptyLinesAffected) { + assert(B.Affected || A.Last->Children.empty()); A.Affected = true; + } A.Last->Next = B.First; B.First->Previous = A.Last; B.First->CanBreakBefore = true; diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp index 624684c7a079b..0b7ac21fd33d3 100644 --- a/clang/unittests/Format/FormatTestSelective.cpp +++ b/clang/unittests/Format/FormatTestSelective.cpp @@ -41,6 +41,11 @@ TEST_F(FormatTestSelective, RemovesTrailingWhitespaceOfFormattedLine) { EXPECT_EQ("int a;", format("int a; ", 0, 0)); EXPECT_EQ("int a;\n", format("int a; \n \n \n ", 0, 0)); EXPECT_EQ("int a;\nint b; ", format("int a; \nint b; ", 0, 0)); + + EXPECT_EQ("void f() {}", format("void f() {\n" + " \n" + "}", + 11, 0)); } TEST_F(FormatTestSelective, FormatsCorrectRegionForLeadingWhitespace) {