[clang] [Clang] Unify interface for accessing template arguments as written for class/variable template specializations (PR #81642)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 1 08:42:08 PDT 2024
================
@@ -1455,21 +1455,17 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
// If this is a class template specialization, print the template
// arguments.
- if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
- ArrayRef<TemplateArgument> Args;
- TypeSourceInfo *TAW = Spec->getTypeAsWritten();
- if (!Policy.PrintCanonicalTypes && TAW) {
- const TemplateSpecializationType *TST =
- cast<TemplateSpecializationType>(TAW->getType());
- Args = TST->template_arguments();
- } else {
- const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
- Args = TemplateArgs.asArray();
- }
+ if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
+ const TemplateParameterList *TParams =
+ S->getSpecializedTemplate()->getTemplateParameters();
+ const auto *TArgAsWritten = S->getTemplateArgsAsWritten();
IncludeStrongLifetimeRAII Strong(Policy);
- printTemplateArgumentList(
- OS, Args, Policy,
- Spec->getSpecializedTemplate()->getTemplateParameters());
+ if (TArgAsWritten && !Policy.PrintCanonicalTypes)
----------------
erichkeane wrote:
This exact pattern happens 2x... it would be nice/useful if we could get a helper function to capture this pattern (perhaps an overload of `printTemplateArgumentList`?).
https://github.com/llvm/llvm-project/pull/81642
More information about the cfe-commits
mailing list