]> granicus.if.org Git - clang/commitdiff
Fixes indentation of empty lines in block comments.
authorManuel Klimek <klimek@google.com>
Tue, 28 May 2013 08:55:01 +0000 (08:55 +0000)
committerManuel Klimek <klimek@google.com>
Tue, 28 May 2013 08:55:01 +0000 (08:55 +0000)
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

lib/Format/BreakableToken.cpp
unittests/Format/FormatTest.cpp

index 1b1827e3f9a9977f95c713664455ead7a642efb5..1fd538e25aeb05f6f7c838685210d4598fc66640 100644 (file)
@@ -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() -
index beebeee50828333b13824707c9329b6a190eb3d4..e05cd8090579751d4821f31aedb8d812279568f0 100644 (file)
@@ -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) {