[clang] [clang-format] Don't align comments over scopes (PR #68743)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 17:49:26 PDT 2023


=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= <bjoern at hazardy.de>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/68743/clang at github.com>


================
@@ -1118,16 +1121,39 @@ void WhitespaceManager::alignTrailingComments() {
       }
     }
 
-    // We don't want to align namespace end comments.
-    const bool DontAlignThisComment =
-        I > 0 && C.NewlinesBefore == 0 &&
-        Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-    if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-        DontAlignThisComment) {
+    // We don't want to align comments which end a scope, which are here
+    // identified by most closing braces.
+    const bool DontAlignThisComment = [&] {
+      if (I == 0 || C.NewlinesBefore > 0)
+        return false;
+      const auto *Tok = Changes[I - 1].Tok;
----------------
owenca wrote:

```suggestion
    auto DontAlignThisComment = [](const auto *Tok) {
```

https://github.com/llvm/llvm-project/pull/68743


More information about the cfe-commits mailing list