[clang] [clang-format] Add anonymous namespace indentation option (PR #244933)

Arnab Sarkar via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 10:59:46 PST 2026


================
@@ -3352,19 +3352,23 @@ void UnwrappedLineParser::parseNamespace() {
          "'namespace' expected");
 
   const FormatToken &InitialToken = *FormatTok;
+  bool IsAnonymousNamespace = InitialToken.is(tok::kw_namespace);
   nextToken();
   if (InitialToken.is(TT_NamespaceMacro)) {
     parseParens();
   } else {
     while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::kw_inline,
                               tok::l_square, tok::period, tok::l_paren) ||
            (Style.isCSharp() && FormatTok->is(tok::kw_union))) {
-      if (FormatTok->is(tok::l_square))
+      if (FormatTok->is(tok::l_square)) {
         parseSquare();
-      else if (FormatTok->is(tok::l_paren))
+      } else if (FormatTok->is(tok::l_paren)) {
         parseParens();
-      else
+      } else {
+        if (FormatTok->is(tok::identifier))
----------------
28arnab wrote:

```cpp
if (FormatTok->is(tok::l_square)) {
        parseSquare();
      } else if (FormatTok->is(tok::l_paren)) {
        parseParens();
      } else {
        IsAnonymousNamespace = false;
        nextToken();
      }
```
This should be sufficient if we exclude `__attribute__(...)`

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


More information about the cfe-commits mailing list