[PATCH] D126620: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 14 09:18:37 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG671eb7dc1e69: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126620/new/

https://reviews.llvm.org/D126620

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp


Index: clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
===================================================================
--- clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
@@ -80,7 +80,7 @@
 template <class T, class U> struct Foo {
   template <unsigned long, class X, class Y> struct Bar;
   template <class Y> struct Bar<0, T, Y> {};
-  // expected-note-re at -1 {{previous declaration {{.*}} 'Bar<0UL, int, type-parameter-0-0>' is here}}
+  // expected-note-re at -1 {{previous declaration {{.*}} 'Bar<0, int, type-parameter-0-0>' is here}}
   template <class Y> struct Bar<0, U, Y> {};
   // expected-error at -1 {{partial specialization 'Bar<0, int, Y>' cannot be redeclared}}
 };
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -80,6 +80,21 @@
     }
   };
 
+  class DefaultTemplateArgsPolicyRAII {
+    PrintingPolicy &Policy;
+    bool Old;
+
+  public:
+    explicit DefaultTemplateArgsPolicyRAII(PrintingPolicy &Policy)
+        : Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) {
+      Policy.SuppressDefaultTemplateArgs = false;
+    }
+
+    ~DefaultTemplateArgsPolicyRAII() {
+      Policy.SuppressDefaultTemplateArgs = Old;
+    }
+  };
+
   class ElaboratedTypePolicyRAII {
     PrintingPolicy &Policy;
     bool SuppressTagKeyword;
@@ -1470,6 +1485,7 @@
   IncludeStrongLifetimeRAII Strong(Policy);
 
   TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+  // FIXME: Null TD never excercised in test suite.
   if (FullyQualify && TD) {
     if (!Policy.SuppressScope)
       AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
@@ -1479,7 +1495,9 @@
     T->getTemplateName().print(OS, Policy);
   }
 
-  printTemplateArgumentList(OS, T->template_arguments(), Policy);
+  DefaultTemplateArgsPolicyRAII TemplateArgs(Policy);
+  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr;
+  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
   spaceBeforePlaceHolder(OS);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126620.436813.patch
Type: text/x-patch
Size: 2149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220614/496c3892/attachment.bin>


More information about the cfe-commits mailing list