Author: Matheus Izvekov Date: 2022-06-14T18:18:24+02:00 New Revision: 671eb7dc1e69fec251e115f4f49865895a43513a
URL: https://github.com/llvm/llvm-project/commit/671eb7dc1e69fec251e115f4f49865895a43513a DIFF: https://github.com/llvm/llvm-project/commit/671eb7dc1e69fec251e115f4f49865895a43513a.diff LOG: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy This redoes D103040 in a way that `AlwaysIncludeTypeForTemplateArgument = false` policy is honored for printing template specialization types. This can be seen for example when printing a canonicalized dependent TemplateSpecializationType which has integral arguments. Signed-off-by: Matheus Izvekov <mizve...@gmail.com> Reviewed By: v.g.vassilev Differential Revision: https://reviews.llvm.org/D126620 Added: Modified: clang/lib/AST/TypePrinter.cpp clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index b5286de5b1cab..38b5a5ab222f5 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -80,6 +80,21 @@ namespace { } }; + 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 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T, 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 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T, 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); } diff --git a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp index 7eddef1cb71f3..871bdc2a58c7b 100644 --- a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp @@ -80,7 +80,7 @@ namespace print_dependent_TemplateSpecializationType { 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@-1 {{previous declaration {{.*}} 'Bar<0UL, int, type-parameter-0-0>' is here}} + // expected-note-re@-1 {{previous declaration {{.*}} 'Bar<0, int, type-parameter-0-0>' is here}} template <class Y> struct Bar<0, U, Y> {}; // expected-error@-1 {{partial specialization 'Bar<0, int, Y>' cannot be redeclared}} }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits