[PATCH] D126620: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 30 13:20:11 PDT 2022
mizvekov created this revision.
Herald added a project: All.
mizvekov updated this revision to Diff 432974.
mizvekov retitled this revision from "WIP" to "[clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy".
mizvekov edited the summary of this revision.
mizvekov added a comment.
mizvekov published this revision for review.
mizvekov added reviewers: rsmith, v.g.vassilev, reikdas.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
.
This redoes D103040 <https://reviews.llvm.org/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 <mizvekov at gmail.com>
Repository:
rG LLVM Github Monorepo
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.432974.patch
Type: text/x-patch
Size: 2149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220530/9314674e/attachment.bin>
More information about the cfe-commits
mailing list