[PATCH] D29486: [clang-format] Re-align broken comment lines where appropriate.

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 3 02:29:55 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL293997: [clang-format] Re-align broken comment lines where appropriate. (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29486?vs=86942&id=86945#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29486

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


Index: cfe/trunk/lib/Format/WhitespaceManager.cpp
===================================================================
--- cfe/trunk/lib/Format/WhitespaceManager.cpp
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp
@@ -164,8 +164,9 @@
   const WhitespaceManager::Change *LastBlockComment = nullptr;
   for (auto &Change : Changes) {
     // Reset the IsTrailingComment flag for changes inside of trailing comments
-    // so they don't get realigned later.
-    if (Change.IsInsideToken)
+    // so they don't get realigned later. Comment line breaks however still need
+    // to be aligned.
+    if (Change.IsInsideToken && Change.NewlinesBefore == 0)
       Change.IsTrailingComment = false;
     Change.StartOfBlockComment = nullptr;
     Change.IndentationOffset = 0;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -11852,6 +11852,40 @@
                    "             // line 3\n"
                    "          b);",
                    getLLVMStyleWithColumns(40)));
+
+  // Align newly broken trailing comments.
+  EXPECT_EQ("int ab; // line\n"
+            "int a;  // long\n"
+            "        // long\n",
+            format("int ab; // line\n"
+                   "int a; // long long\n",
+                   getLLVMStyleWithColumns(15)));
+  EXPECT_EQ("int ab; // line\n"
+            "int a;  // long\n"
+            "        // long\n"
+            "        // long",
+            format("int ab; // line\n"
+                   "int a; // long long\n"
+                   "       // long",
+                   getLLVMStyleWithColumns(15)));
+  EXPECT_EQ("int ab; // line\n"
+            "int a;  // long\n"
+            "        // long\n"
+            "pt c;   // long",
+            format("int ab; // line\n"
+                   "int a; // long long\n"
+                   "pt c; // long",
+                   getLLVMStyleWithColumns(15)));
+  EXPECT_EQ("int ab; // line\n"
+            "int a;  // long\n"
+            "        // long\n"
+            "\n"
+            "// long",
+            format("int ab; // line\n"
+                   "int a; // long long\n"
+                   "\n"
+                   "// long",
+                   getLLVMStyleWithColumns(15)));
 }
 } // end namespace
 } // end namespace format


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29486.86945.patch
Type: text/x-patch
Size: 2410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170203/8e9e84f5/attachment.bin>


More information about the cfe-commits mailing list