Skip to content

Conversation

@Michael137
Copy link
Member

Split out from #169445 where we introduce an additional mode to SuppressTagKeywordMode.

Prepares PrintingPolicy::SuppressTagKeyword to take enum values. Currently the main use of this flag is to prevent the tag keyword from being printed when we already printed it for the outer elaborated type. Hence I chose the name SuppressTagKeywordMode::InElaboratedNames. But happy to consider other names

In preparation for a follow-up patch that adds a new mode to this enum.
@llvmbot llvmbot added clang-tools-extra lldb clangd clang-tidy clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:as-a-library libclang and C++ API ClangIR Anything related to the ClangIR project labels Dec 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 8, 2025

@llvm/pr-subscribers-lldb
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: Michael Buch (Michael137)

Changes

Split out from #169445 where we introduce an additional mode to SuppressTagKeywordMode.

Prepares PrintingPolicy::SuppressTagKeyword to take enum values. Currently the main use of this flag is to prevent the tag keyword from being printed when we already printed it for the outer elaborated type. Hence I chose the name SuppressTagKeywordMode::InElaboratedNames. But happy to consider other names


Patch is 22.65 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171160.diff

17 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp (+2-1)
  • (modified) clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp (+2-1)
  • (modified) clang-tools-extra/clang-tidy/utils/Matchers.cpp (+2-1)
  • (modified) clang-tools-extra/clangd/AST.cpp (+2-1)
  • (modified) clang-tools-extra/clangd/Hover.cpp (+4-1)
  • (modified) clang/include/clang/AST/PrettyPrinter.h (+18-7)
  • (modified) clang/lib/AST/Expr.cpp (+4-1)
  • (modified) clang/lib/AST/InferAlloc.cpp (+2-1)
  • (modified) clang/lib/AST/NestedNameSpecifier.cpp (+2-1)
  • (modified) clang/lib/AST/TypePrinter.cpp (+9-5)
  • (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+2-1)
  • (modified) clang/lib/Index/USRGeneration.cpp (+2-1)
  • (modified) clang/tools/libclang/CIndex.cpp (+8-3)
  • (modified) clang/unittests/AST/DeclPrinterTest.cpp (+54-37)
  • (modified) clang/unittests/AST/TypePrinterTest.cpp (+6-5)
  • (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+2-1)
  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+4-2)
diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
index 4d26c39fcbd18..5aa25e44d8735 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -187,7 +187,8 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
 
       QualType NoRefType = (*InvocationParmType)->getPointeeType();
       PrintingPolicy PolicyWithSuppressedTag(getLangOpts());
-      PolicyWithSuppressedTag.SuppressTagKeyword = true;
+      PolicyWithSuppressedTag.SuppressTagKeyword = llvm::to_underlying(
+          PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
       PolicyWithSuppressedTag.SuppressUnwrittenScope = true;
       std::string ExpectParmTypeName =
           NoRefType.getAsString(PolicyWithSuppressedTag);
diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
index 7ef8ef3d947f3..6acbb9bf12fa6 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -72,7 +72,8 @@ void StaticAccessedThroughInstanceCheck::check(
 
   const ASTContext *AstContext = Result.Context;
   PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
   PrintingPolicyWithSuppressedTag.PrintAsCanonical =
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index b1591fb8e3619..6d6ca0b36335e 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -35,7 +35,8 @@ bool MatchesAnyListedTypeNameMatcher::matches(
   PrintingPolicyWithSuppressedTag.PrintAsCanonical = CanonicalTypes;
   PrintingPolicyWithSuppressedTag.FullyQualifiedName = true;
   PrintingPolicyWithSuppressedTag.SuppressScope = false;
-  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
   std::string TypeName =
       Node.getUnqualifiedType().getAsString(PrintingPolicyWithSuppressedTag);
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 0dcff2eae05e7..a4677efe63b7a 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -419,7 +419,8 @@ std::string printType(const QualType QT, const DeclContext &CurContext,
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   PrintingPolicy PP(CurContext.getParentASTContext().getPrintingPolicy());
-  PP.SuppressTagKeyword = true;
+  PP.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   PP.SuppressUnwrittenScope = true;
   PP.FullyQualifiedName = FullyQualify;
 
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 34369e188d4ec..b00eb5c8ed9d4 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -176,7 +176,10 @@ HoverInfo::PrintedType printType(QualType QT, ASTContext &ASTCtx,
   // tag for extra clarity. This isn't very idiomatic, so don't attempt it for
   // complex cases, including pointers/references, template specializations,
   // etc.
-  if (!QT.isNull() && !QT.hasQualifiers() && PP.SuppressTagKeyword) {
+  if (!QT.isNull() && !QT.hasQualifiers() &&
+      PP.SuppressTagKeyword ==
+          llvm::to_underlying(
+              PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames)) {
     if (auto *TT = llvm::dyn_cast<TagType>(QT.getTypePtr());
         TT && TT->isCanonicalUnqualified())
       OS << TT->getDecl()->getKindName() << " ";
diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h
index 48105b3b9d4cd..6946ea17987f6 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -58,11 +58,24 @@ class PrintingCallbacks {
 struct PrintingPolicy {
   enum class SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
 
+  /// Dictates when type printing should skip printing the tag keyword.
+  enum class SuppressTagKeywordMode : uint8_t {
+    /// Never suppress tag keyword.
+    None,
+
+    /// Suppress keyword when printing the inner type of elaborated types,
+    /// (as the tag keyword is part of the elaborated type):
+    InElaboratedNames
+  };
+
   /// 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),
+        SuppressTagKeyword(llvm::to_underlying(
+            LO.CPlusPlus ? SuppressTagKeywordMode::InElaboratedNames
+                         : SuppressTagKeywordMode::None)),
+        IncludeTagDefinition(false), SuppressScope(false),
+        SuppressUnwrittenScope(false),
         SuppressInlineNamespace(
             llvm::to_underlying(SuppressInlineNamespaceMode::Redundant)),
         SuppressInitializers(false), ConstantArraySizeAsWritten(false),
@@ -88,7 +101,8 @@ struct PrintingPolicy {
   /// construct). This should not be used if a real LangOptions object is
   /// available.
   void adjustForCPlusPlus() {
-    SuppressTagKeyword = true;
+    SuppressTagKeyword =
+        llvm::to_underlying(SuppressTagKeywordMode::InElaboratedNames);
     Bool = true;
     UseVoidForZeroParams = false;
   }
@@ -115,13 +129,10 @@ struct PrintingPolicy {
 
   /// Whether type printing should skip printing the tag keyword.
   ///
-  /// This is used when printing the inner type of elaborated types,
-  /// (as the tag keyword is part of the elaborated type):
-  ///
   /// \code
   /// struct Geometry::Point;
   /// \endcode
-  LLVM_PREFERRED_TYPE(bool)
+  LLVM_PREFERRED_TYPE(SuppressTagKeywordMode)
   unsigned SuppressTagKeyword : 1;
 
   /// When true, include the body of a tag definition.
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index ca7f3e16a9276..426733785850a 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -759,7 +759,10 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
     PrettyCallbacks PrettyCB(Context.getLangOpts());
     Policy.Callbacks = &PrettyCB;
     if (IK == PredefinedIdentKind::Function && ForceElaboratedPrinting)
-      Policy.SuppressTagKeyword = !LO.MSVCCompat;
+      Policy.SuppressTagKeyword = llvm::to_underlying(
+          LO.MSVCCompat
+              ? PrintingPolicy::SuppressTagKeywordMode::None
+              : PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
     std::string Proto;
     llvm::raw_string_ostream POut(Proto);
 
diff --git a/clang/lib/AST/InferAlloc.cpp b/clang/lib/AST/InferAlloc.cpp
index e439ed4dbb386..b161fab6ca3f5 100644
--- a/clang/lib/AST/InferAlloc.cpp
+++ b/clang/lib/AST/InferAlloc.cpp
@@ -184,7 +184,8 @@ infer_alloc::getAllocTokenMetadata(QualType T, const ASTContext &Ctx) {
 
   // Get unique type name.
   PrintingPolicy Policy(Ctx.getLangOpts());
-  Policy.SuppressTagKeyword = true;
+  Policy.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   Policy.FullyQualifiedName = true;
   llvm::raw_svector_ostream TypeNameOS(ATMD.TypeName);
   T.getCanonicalType().print(TypeNameOS, Policy);
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp
index c6af91f5c0083..2a227f31026d8 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -111,7 +111,8 @@ void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
     break;
   case Kind::Type: {
     PrintingPolicy InnerPolicy(Policy);
-    InnerPolicy.SuppressTagKeyword = true;
+    InnerPolicy.SuppressTagKeyword = llvm::to_underlying(
+        PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
     QualType(getAsType(), 0).print(OS, InnerPolicy);
     break;
   }
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index d2881d5ac518a..06e112b7e840b 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -92,19 +92,21 @@ class DefaultTemplateArgsPolicyRAII {
 
 class ElaboratedTypePolicyRAII {
   PrintingPolicy &Policy;
-  bool SuppressTagKeyword;
+  PrintingPolicy::SuppressTagKeywordMode SuppressTagKeyword;
   bool SuppressScope;
 
 public:
   explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
-    SuppressTagKeyword = Policy.SuppressTagKeyword;
+    SuppressTagKeyword = static_cast<PrintingPolicy::SuppressTagKeywordMode>(
+        Policy.SuppressTagKeyword);
     SuppressScope = Policy.SuppressScope;
-    Policy.SuppressTagKeyword = true;
+    Policy.SuppressTagKeyword = llvm::to_underlying(
+        PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
     Policy.SuppressScope = true;
   }
 
   ~ElaboratedTypePolicyRAII() {
-    Policy.SuppressTagKeyword = SuppressTagKeyword;
+    Policy.SuppressTagKeyword = llvm::to_underlying(SuppressTagKeyword);
     Policy.SuppressScope = SuppressScope;
   }
 };
@@ -1521,7 +1523,9 @@ void TypePrinter::printTagType(const TagType *T, raw_ostream &OS) {
   bool HasKindDecoration = false;
 
   if (T->isCanonicalUnqualified()) {
-    if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) {
+    if (Policy.SuppressTagKeyword ==
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None) &&
+        !D->getTypedefNameForAnonDecl()) {
       HasKindDecoration = true;
       OS << D->getKindName();
       OS << ' ';
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index 24b106b4bcee7..3cdcad7dfa75d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -101,7 +101,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
       llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   policy.AlwaysIncludeTypeForTemplateArgument = true;
   policy.PrintAsCanonical = true;
-  policy.SuppressTagKeyword = true;
+  policy.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
 
   if (recordDecl->getIdentifier())
     QualType(astContext.getCanonicalTagType(recordDecl))
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 08835ea786997..d7c5a813e660d 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -656,7 +656,8 @@ static void printQualifier(llvm::raw_ostream &Out, const LangOptions &LangOpts,
                            NestedNameSpecifier NNS) {
   // FIXME: Encode the qualifier, don't just print it.
   PrintingPolicy PO(LangOpts);
-  PO.SuppressTagKeyword = true;
+  PO.SuppressTagKeyword = llvm::to_underlying(
+      PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   PO.SuppressUnwrittenScope = true;
   PO.ConstantArraySizeAsWritten = false;
   PO.AnonymousTagLocations = false;
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 32e84248c1b27..6b17c02b21ffa 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5342,7 +5342,8 @@ CXString clang_getCursorSpelling(CXCursor C) {
 
       PrintingPolicy Policy = Ctx.getPrintingPolicy();
       Policy.FullyQualifiedName = true;
-      Policy.SuppressTagKeyword = false;
+      Policy.SuppressTagKeyword =
+          llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
       return cxstring::createDup(T.getAsString(Policy));
     }
     case CXCursor_TemplateRef: {
@@ -5642,7 +5643,9 @@ clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy,
   case CXPrintingPolicy_SuppressSpecifiers:
     return P->SuppressSpecifiers;
   case CXPrintingPolicy_SuppressTagKeyword:
-    return P->SuppressTagKeyword;
+    return P->SuppressTagKeyword ==
+           llvm::to_underlying(
+               PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
   case CXPrintingPolicy_IncludeTagDefinition:
     return P->IncludeTagDefinition;
   case CXPrintingPolicy_SuppressScope:
@@ -5710,7 +5713,9 @@ void clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy,
     P->SuppressSpecifiers = Value;
     return;
   case CXPrintingPolicy_SuppressTagKeyword:
-    P->SuppressTagKeyword = Value;
+    P->SuppressTagKeyword = llvm::to_underlying(
+        Value ? PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames
+              : PrintingPolicy::SuppressTagKeywordMode::None);
     return;
   case CXPrintingPolicy_IncludeTagDefinition:
     P->IncludeTagDefinition = Value;
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index a412a9813b470..4649994bf4b5b 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -356,40 +356,44 @@ TEST(DeclPrinter, TestCXXRecordDecl11) {
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl12) {
-  ASSERT_TRUE(PrintedDeclCXX98Matches("struct S { int x; };"
-                                      "namespace NS { class C {};}"
-                                      "void foo() {using namespace NS; C c;}",
-                                      "foo",
-                                      "void foo() {\nusing namespace NS;\n"
-                                      "C c;\n}\n",
-                                      [](PrintingPolicy &Policy) {
-                                        Policy.SuppressTagKeyword = false;
-                                        Policy.SuppressScope = true;
-                                        Policy.TerseOutput = false;
-                                      }));
+  ASSERT_TRUE(PrintedDeclCXX98Matches(
+      "struct S { int x; };"
+      "namespace NS { class C {};}"
+      "void foo() {using namespace NS; C c;}",
+      "foo",
+      "void foo() {\nusing namespace NS;\n"
+      "C c;\n}\n",
+      [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+        Policy.SuppressScope = true;
+        Policy.TerseOutput = false;
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl13) {
-  ASSERT_TRUE(PrintedDeclCXX98Matches("struct S { int x; };"
-                                      "S s1;"
-                                      "S foo() {return s1;}",
-                                      "foo", "S foo() {\nreturn s1;\n}\n",
-                                      [](PrintingPolicy &Policy) {
-                                        Policy.SuppressTagKeyword = false;
-                                        Policy.SuppressScope = true;
-                                        Policy.TerseOutput = false;
-                                      }));
+  ASSERT_TRUE(PrintedDeclCXX98Matches(
+      "struct S { int x; };"
+      "S s1;"
+      "S foo() {return s1;}",
+      "foo", "S foo() {\nreturn s1;\n}\n", [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+        Policy.SuppressScope = true;
+        Policy.TerseOutput = false;
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl14) {
-  ASSERT_TRUE(PrintedDeclCXX98Matches("struct S { int x; };"
-                                      "S foo(S s1) {return s1;}",
-                                      "foo", "S foo(S s1) {\nreturn s1;\n}\n",
-                                      [](PrintingPolicy &Policy) {
-                                        Policy.SuppressTagKeyword = false;
-                                        Policy.SuppressScope = true;
-                                        Policy.TerseOutput = false;
-                                      }));
+  ASSERT_TRUE(PrintedDeclCXX98Matches(
+      "struct S { int x; };"
+      "S foo(S s1) {return s1;}",
+      "foo", "S foo(S s1) {\nreturn s1;\n}\n", [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+        Policy.SuppressScope = true;
+        Policy.TerseOutput = false;
+      }));
 }
 TEST(DeclPrinter, TestCXXRecordDecl15) {
   ASSERT_TRUE(PrintedDeclCXX98Matches(
@@ -400,7 +404,8 @@ TEST(DeclPrinter, TestCXXRecordDecl15) {
       "S foo(S s1, NS::C c1) {\nusing namespace NS;\n"
       "C c;\nreturn s1;\n}\n",
       [](PrintingPolicy &Policy) {
-        Policy.SuppressTagKeyword = false;
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
         Policy.SuppressScope = true;
         Policy.TerseOutput = false;
       }));
@@ -1385,8 +1390,10 @@ TEST(DeclPrinter, TestCXXRecordDecl17) {
       "template<typename T> struct Z {};"
       "struct X {};"
       "Z<X> A;",
-      "A", "Z<X> A",
-      [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }));
+      "A", "Z<X> A", [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl18) {
@@ -1397,8 +1404,10 @@ TEST(DeclPrinter, TestCXXRecordDecl18) {
       "template <typename T1, int>"
       "struct Y{};"
       "Y<Z<X>, 2> B;",
-      "B", "Y<Z<X>, 2> B",
-      [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }));
+      "B", "Y<Z<X>, 2> B", [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl19) {
@@ -1409,8 +1418,10 @@ TEST(DeclPrinter, TestCXXRecordDecl19) {
       "template <typename T1, int>"
       "struct Y{};"
       "Y<Z<X>, 2> B;",
-      "B", "Y<Z<X>, 2> B",
-      [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; }));
+      "B", "Y<Z<X>, 2> B", [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword = llvm::to_underlying(
+            PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl20) {
@@ -1430,7 +1441,10 @@ TEST(DeclPrinter, TestCXXRecordDecl20) {
       "Outer<Inner<int, 10>, 5>::NestedStruct nestedInstance(100);",
       "nestedInstance",
       "Outer<Inner<int, 10>, 5>::NestedStruct nestedInstance(100)",
-      [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }));
+      [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword =
+            llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None);
+      }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl21) {
@@ -1450,7 +1464,10 @@ TEST(DeclPrinter, TestCXXRecordDecl21) {
       "Outer<Inner<int, 10>, 5>::NestedStruct nestedInstance(100);",
       "nestedInstance",
       "Outer<Inner<int, 10>, 5>::NestedStruct nestedInstance(100)",
-      [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; }));
+      [](PrintingPolicy &Policy) {
+        Policy.SuppressTagKeyword = llvm::to_underlying(
+            PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
+      }));
 }
 
 TEST(DeclPrinter, TestFunctionParamUglified) {
diff --git a/clang/unittests/AST/TypePrinterTest.cpp b/clang/unittests/AST/TypePrinterTest.cpp
index 3cadf9b265bd1..b5360c2507cda 100644
--- a/clang/unittests/AST/TypePrinterTest.cpp
+++ b/clang/unittests/AST/TypePrinterTest.cpp
@@ -161,11 +161,12 @@ TEST(TypePrinter, TemplateArgumentsSubstitution) {
        }
   )cpp";
   auto Matcher = typedefNameDecl(hasName("A"), hasType(qualType().bind("id")));
-  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher, "X<int>",
-                                 [](PrintingPolicy &Policy) {
-                                   Policy.SuppressTagKeyword = false;
-                       ...
[truncated]

@mizvekov
Copy link
Contributor

mizvekov commented Dec 8, 2025

As I pointed out in the original patch, maybe there was a confusion on my part where I assumed we would have a three valued enum, but the direction actually would make it four valued, and these would be controlling the suppression of the keyword in orthogonal places.

Can you clarify?

I don't mind bool vs two valued enum, if that's your preference, but the tying up of two separate conditions into one variable is making the other patch look awkward.

@Michael137
Copy link
Member Author

As I pointed out in the original patch, maybe there was a confusion on my part where I assumed we would have a three valued enum, but the direction actually would make it four valued, and these would be controlling the suppression of the keyword in orthogonal places.

Can you clarify?

I don't mind bool vs two valued enum, if that's your preference, but the tying up of two separate conditions into one variable is making the other patch look awkward.

Actually it is possible to have made it a three-valued enum, but reasoning about it was a bit unclear if someone wasn't very familiar with the details. I think two booleans actually ended up looking clearer, so I did that for now

@Michael137 Michael137 closed this Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:as-a-library libclang and C++ API clang:frontend Language frontend issues, e.g. anything involving "Sema" clang-tidy clang-tools-extra clangd ClangIR Anything related to the ClangIR project lldb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants