https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/170802

The enum cases for `SuppressInlineNamespaceMode` leaked into the rest of 
`PrintingPolicy`, meaning if we wanted to introduce another enum (which I'm 
planning on doing in an unrelated PR), then `All`/`None`/`Redundant` are all 
already taken, which are quite useful names.

This patch turns `SuppressInlineNamespaceMode` into an `enum class`, freeing up 
the names for use by other future enums in `PrintingPolicy`.

Unfortunately that means we have to cast the values when assigning to 
`PrintingPolicy::SuppressInlineNamespace`, because its actual type is 
`unsigned`. But if we ever make the bitfields have proper enumeration types 
(which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those 
casts.

This caught three instances of assigning booleans to `SuppressInlineNamespace`. 
I added a FIXME in LLDB to check what the intended value of the enum should be.

>From 488a3a49972c5b64e617b00399e79c6ad0164c90 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Fri, 5 Dec 2025 13:43:17 +0800
Subject: [PATCH] [clang][TypePrinter][NFC] Make SuppressInlineNamespaceMode an
 enum class

The enum cases for `SuppressInlineNamespaceMode` leaked into the rest of 
`PrintingPolicy`, meaning if we wanted to introduce another enum (which I'm 
planning on doing in an unrelated PR), then `All`/`None`/`Redundant` are all 
already taken, which are quite useful names.

This patch turns `SuppressInlineNamespaceMode` into an `enum class`, freeing up 
the names for use by other future enums in `PrintingPolicy`.

Unfortunately that means we have to cast the values when assigning to 
`PrintingPolicy::SuppressInlineNamespace`, because it's actual type is 
`unsigned`. But if we ever make the bitfields have proper enumeration types 
(which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those 
casts.

This caught three instances of assigning booleans to `SuppressInlineNamespace`. 
I added a FIXME in LLDB to check what the intended value of the enum should be.
---
 clang/include/clang/AST/PrettyPrinter.h                  | 5 +++--
 clang/lib/AST/Decl.cpp                                   | 6 ++++--
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp            | 4 ++--
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp                    | 3 ++-
 clang/lib/CodeGen/CGDebugInfo.cpp                        | 2 +-
 clang/lib/CodeGen/CodeGenTypes.cpp                       | 2 +-
 lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 7 +++++--
 7 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index fd995a653d167..289dff7b23010 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -55,14 +55,15 @@ class PrintingCallbacks {
 /// This type is intended to be small and suitable for passing by value.
 /// It is very frequently copied.
 struct PrintingPolicy {
-  enum SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
+  enum class SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
 
   /// Create a default printing policy for the specified language.
   PrintingPolicy(const LangOptions &LO)
       : Indentation(2), SuppressSpecifiers(false),
         SuppressTagKeyword(LO.CPlusPlus), IncludeTagDefinition(false),
         SuppressScope(false), SuppressUnwrittenScope(false),
-        SuppressInlineNamespace(SuppressInlineNamespaceMode::Redundant),
+        SuppressInlineNamespace(
+            llvm::to_underlying(SuppressInlineNamespaceMode::Redundant)),
         SuppressInitializers(false), ConstantArraySizeAsWritten(false),
         AnonymousTagLocations(true), SuppressStrongLifetime(false),
         SuppressLifetimeQualifiers(false),
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 591457b1d66b4..4444b10db8cc0 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1753,9 +1753,11 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
     // Suppress inline namespace if it doesn't make the result ambiguous.
     if (Ctx->isInlineNamespace() && NameInScope) {
       if (P.SuppressInlineNamespace ==
-              PrintingPolicy::SuppressInlineNamespaceMode::All ||
+              llvm::to_underlying(
+                  PrintingPolicy::SuppressInlineNamespaceMode::All) ||
           (P.SuppressInlineNamespace ==
-               PrintingPolicy::SuppressInlineNamespaceMode::Redundant &&
+               llvm::to_underlying(
+                   PrintingPolicy::SuppressInlineNamespaceMode::Redundant) &&
            cast<NamespaceDecl>(Ctx)->isRedundantInlineQualifierFor(
                NameInScope))) {
         continue;
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index fbb8b49676045..a556ffca96903 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -654,9 +654,9 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl 
&Node) const {
 
     PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
     Policy.SuppressUnwrittenScope = SkipUnwritten;
-    Policy.SuppressInlineNamespace =
+    Policy.SuppressInlineNamespace = llvm::to_underlying(
         SkipUnwritten ? PrintingPolicy::SuppressInlineNamespaceMode::All
-                      : PrintingPolicy::SuppressInlineNamespaceMode::None;
+                      : PrintingPolicy::SuppressInlineNamespaceMode::None);
     Node.printQualifiedName(OS, Policy);
 
     const StringRef FullName = OS.str();
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp 
b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index efc2c6c0ba500..24b106b4bcee7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -97,7 +97,8 @@ std::string CIRGenTypes::getRecordTypeName(const 
clang::RecordDecl *recordDecl,
   llvm::raw_svector_ostream outStream(typeName);
 
   PrintingPolicy policy = recordDecl->getASTContext().getPrintingPolicy();
-  policy.SuppressInlineNamespace = false;
+  policy.SuppressInlineNamespace =
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   policy.AlwaysIncludeTypeForTemplateArgument = true;
   policy.PrintAsCanonical = true;
   policy.SuppressTagKeyword = true;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index c50f372c1f331..5a83c151901f9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -417,7 +417,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   }
 
   PP.SuppressInlineNamespace =
-      PrintingPolicy::SuppressInlineNamespaceMode::None;
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   PP.PrintAsCanonical = true;
   PP.UsePreferredNames = false;
   PP.AlwaysIncludeTypeForTemplateArgument = true;
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index ea31195b7f92e..be862cf07f177 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -62,7 +62,7 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
   // FullyQualifiedNames.
   PrintingPolicy Policy = RD->getASTContext().getPrintingPolicy();
   Policy.SuppressInlineNamespace =
-      PrintingPolicy::SuppressInlineNamespaceMode::None;
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
 
   // Name the codegen type after the typedef name
   // if there is no tag type name available
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index aa8d309fbc730..2cb4a46130c84 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2149,7 +2149,8 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() {
   printing_policy.SuppressTagKeyword = true;
   // Inline namespaces are important for some type formatters (e.g., libc++
   // and libstdc++ are differentiated by their inline namespaces).
-  printing_policy.SuppressInlineNamespace = false;
+  printing_policy.SuppressInlineNamespace =
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   printing_policy.SuppressUnwrittenScope = false;
   // Default arguments are also always important for type formatters. Otherwise
   // we would need to always specify two type names for the setups where we do
@@ -3870,7 +3871,9 @@ 
TypeSystemClang::GetDisplayTypeName(lldb::opaque_compiler_type_t type) {
   printing_policy.SuppressTagKeyword = true;
   printing_policy.SuppressScope = false;
   printing_policy.SuppressUnwrittenScope = true;
-  printing_policy.SuppressInlineNamespace = true;
+  // FIXME: should we suppress "All" inline namespaces?
+  printing_policy.SuppressInlineNamespace = llvm::to_underlying(
+      PrintingPolicy::SuppressInlineNamespaceMode::Redundant);
   return ConstString(qual_type.getAsString(printing_policy));
 }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to