[PATCH] D29326: [clang-format] Fix reflow in block comment lines with leading whitespace.

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 31 06:43:03 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL293633: [clang-format] Fix reflow in block comment lines with leading whitespace. (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29326?vs=86419&id=86422#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29326

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -521,10 +521,15 @@
     unsigned PreviousEndColumn,
     unsigned ColumnLimit,
     Split SplitBefore) const {
-    if (SplitBefore.first == StringRef::npos ||
-        SplitBefore.first + SplitBefore.second < Content[LineIndex].size()) {
-      // A piece of line, not the whole, gets reflown.
-      return getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
+  if (SplitBefore.first == StringRef::npos ||
+      // Block comment line contents contain the trailing whitespace after the
+      // decoration, so the need of left trim. Note that this behavior is
+      // consistent with the breaking of block comments where the indentation of
+      // a broken line is uniform across all the lines of the block comment.
+      SplitBefore.first + SplitBefore.second <
+          Content[LineIndex].ltrim().size()) {
+    // A piece of line, not the whole, gets reflown.
+    return getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
   } else {
     // The whole line gets reflown, need to check if we need to insert a break
     // for the postfix or not.
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1960,6 +1960,23 @@
                    " * longg */",
                    getLLVMStyleWithColumns(20)));
 
+  // Reflow lines with leading whitespace.
+  EXPECT_EQ("{\n"
+            "  /*\n"
+            "   * long long long\n"
+            "   * long long long\n"
+            "   * long long long\n"
+            "   */\n"
+            "}",
+            format("{\n"
+                   "/*\n"
+                   " * long long long long\n"
+                   " *   long\n"
+                   " * long long long long\n"
+                   " */\n"
+                   "}",
+                   getLLVMStyleWithColumns(20)));
+
   // Break single line block comments that are first in the line with ' *'
   // decoration.
   EXPECT_EQ("/* long long long\n"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29326.86422.patch
Type: text/x-patch
Size: 2266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170131/f6f05c5c/attachment.bin>


More information about the cfe-commits mailing list