diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index c84d9afdd4e8ee5d1736163d89009b7ee9fc9318..66e935abdf558d6e7feda8a750ccf4fdd3be7bc4 100644 --- a/lib/Format/BreakableToken.cpp +++ b/lib/Format/BreakableToken.cpp @@ -277,6 +277,8 @@ BreakableBlockComment::BreakableBlockComment( // If the last line is empty, the closing "*/" will have a star. if (i + 1 == e && Lines[i].empty()) break; + if (!Lines[i].empty() && i + 1 != e && Decoration.startswith(Lines[i])) + continue; while (!Lines[i].startswith(Decoration)) Decoration = Decoration.substr(0, Decoration.size() - 1); } @@ -297,14 +299,18 @@ BreakableBlockComment::BreakableBlockComment( } continue; } + // The first line already excludes the star. // For all other lines, adjust the line to exclude the star and // (optionally) the first whitespace. - StartOfLineColumn[i] += Decoration.size(); - Lines[i] = Lines[i].substr(Decoration.size()); - LeadingWhitespace[i] += Decoration.size(); - IndentAtLineBreak = - std::min<int>(IndentAtLineBreak, std::max(0, StartOfLineColumn[i])); + unsigned DecorationSize = + Decoration.startswith(Lines[i]) ? Lines[i].size() : Decoration.size(); + StartOfLineColumn[i] += DecorationSize; + Lines[i] = Lines[i].substr(DecorationSize); + LeadingWhitespace[i] += DecorationSize; + if (!Decoration.startswith(Lines[i])) + IndentAtLineBreak = + std::min<int>(IndentAtLineBreak, std::max(0, StartOfLineColumn[i])); } IndentAtLineBreak = std::max<unsigned>(IndentAtLineBreak, Decoration.size()); DEBUG({ diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a1817ea1926ce59b57a3b039a751d9fc2385ad6e..e5fe7b5091aa43a94d91f7e5d15bdf3d34e7b751 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1621,6 +1621,17 @@ TEST_F(FormatTest, SplitsLongLinesInComments) { " */", getLLVMStyleWithColumns(20))); + EXPECT_EQ("/**\n" + " * multiline block\n" + " * comment\n" + " *\n" + " */", + format("/**\n" + " * multiline block comment\n" + " *\n" + " */", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" "\n" "\n" @@ -6525,7 +6536,7 @@ TEST_F(FormatTest, BlockComments) { EXPECT_EQ("/*\n" "*\n" " * aaaaaa\n" - "*aaaaaa\n" + " * aaaaaa\n" "*/", format("/*\n" "*\n"