[clang] [Clang] Unify interface for accessing template arguments as written for class/variable template specializations (PR #81642)
Krystian Stasiowski via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 17 07:18:19 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)
----------------
sdkrystian wrote:
@erichkeane Unfortunately, this pattern occurs in separate files (`DeclPrinter.cpp` and `TypePrinter.cpp`), hence the duplication...
https://github.com/llvm/llvm-project/pull/81642
More information about the cfe-commits
mailing list