summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/BreakableToken.cpp13
-rw-r--r--clang/unittests/Format/FormatTest.cpp7
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 1b1827e3f9a..1fd538e25ae 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -321,8 +321,17 @@ BreakableBlockComment::replaceWhitespaceBefore(unsigned LineIndex,
if (LineIndex == 0)
return;
StringRef Prefix = Decoration;
- if (LineIndex + 1 == Lines.size() && Lines[LineIndex].empty())
- Prefix = "";
+ if (Lines[LineIndex].empty()) {
+ if (LineIndex + 1 == Lines.size()) {
+ // If the last line is empty, we don't need a prefix, as the */ will line
+ // up with the decoration (if it exists).
+ Prefix = "";
+ } else if (!Decoration.empty()) {
+ // For other empty lines, if we do have a decoration, adapt it to not
+ // contain a trailing whitespace.
+ Prefix = Prefix.substr(0, 1);
+ }
+ }
unsigned WhitespaceOffsetInToken =
Lines[LineIndex].data() - Tok.TokenText.data() -
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index beebeee5082..e05cd809057 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -771,6 +771,13 @@ TEST_F(FormatTest, AlignsMultiLineComments) {
format(" /*\n"
" Don't try to outdent if there's not enough inentation.\n"
" */"));
+
+ EXPECT_EQ("int i; /* Comment with empty...\n"
+ " *\n"
+ " * line. */",
+ format("int i; /* Comment with empty...\n"
+ " *\n"
+ " * line. */"));
}
TEST_F(FormatTest, SplitsLongCxxComments) {
OpenPOWER on IntegriCloud