llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

<details>
<summary>Changes</summary>

Fixes #<!-- -->92530.

---
Full diff: https://github.com/llvm/llvm-project/pull/98427.diff


2 Files Affected:

- (modified) clang/lib/Format/WhitespaceManager.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTestComments.cpp (+17) 


``````````diff
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 50531aee9d597..a31874a7c3195 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1116,7 +1116,7 @@ void WhitespaceManager::alignTrailingComments() {
       // leave the comments.
       if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
         break;
-      C.Spaces = OriginalSpaces;
+      C.Spaces = C.NewlinesBefore > 0 ? C.Tok->OriginalColumn : OriginalSpaces;
       continue;
     }
 
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 3e75707a9faec..8f84d59cbb2e2 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3145,6 +3145,23 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
                    "int bar = 1234;       // This is a very long comment\n"
                    "          // which is wrapped arround.",
                    Style));
+
+  Style = getLLVMStyle();
+  Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Leave;
+  Style.TabWidth = 2;
+  Style.UseTab = FormatStyle::UT_ForIndentation;
+  verifyNoChange("{\n"
+                 "\t// f\n"
+                 "\tf();\n"
+                 "\n"
+                 "\t// g\n"
+                 "\tg();\n"
+                 "\t{\n"
+                 "\t\t// h();  // h\n"
+                 "\t\tfoo();  // foo\n"
+                 "\t}\n"
+                 "}",
+                 Style);
 }
 
 TEST_F(FormatTestComments, DontAlignNamespaceComments) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/98427
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to