[clang] [clang-format] Support BraceWrapping.AfterNamespace with AllowShortNamespacesOnASingleLine (PR #123010)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 19:29:50 PST 2025


================
@@ -632,24 +631,37 @@ class LineJoiner {
     if (Limit == 0)
       return 0;
 
-    assert(I[1]);
-    const auto &L1 = *I[1];
+    // The merging code is relative to the opening namespace brace, which could
+    // be either on the first or second line due to the brace wrapping rules.
+    const bool OpenBraceWrapped = Style.BraceWrapping.AfterNamespace;
+    const auto BraceOpenLine = I + OpenBraceWrapped;
+
+    assert(*BraceOpenLine);
+    if ((*BraceOpenLine)->Last->isNot(tok::l_brace))
+      return 0;
+
+    if (std::distance(BraceOpenLine, E) <= 2)
+      return 0;
+
+    if (BraceOpenLine[0]->Last->is(TT_LineComment))
----------------
owenca wrote:

```suggestion
    if (BraceOpenLine[0]->Last->is(tok::comment))
```
I missed it last time.

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


More information about the cfe-commits mailing list