From: Manuel Klimek Date: Tue, 28 May 2013 08:55:01 +0000 (+0000) Subject: Fixes indentation of empty lines in block comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5cc4bf2699b0542f352738f84eee373cfcf670f;p=clang Fixes indentation of empty lines in block comments. Block comment indentation of empty lines regressed, as we did not have a test for it. /* Comment with... * * empty line. */ is now formatted correctly again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182757 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index 1b1827e3f9..1fd538e25a 100644 --- a/lib/Format/BreakableToken.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index beebeee508..e05cd80905 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {