[clang] [clang] Implement CTAD for type alias template. (PR #77890)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 11:26:41 PST 2024


================
@@ -10598,10 +10598,36 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
   if (TemplateName.isDependent())
     return SubstAutoTypeDependent(TSInfo->getType());
 
-  // We can only perform deduction for class templates.
+  // We can only perform deduction for class templates or alias templates.
   auto *Template =
       dyn_cast_or_null<ClassTemplateDecl>(TemplateName.getAsTemplateDecl());
+  TemplateDecl* LookupTemplateDecl = Template;
+  if (!Template && getLangOpts().CPlusPlus20) { // type alias template
+    if (auto *AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>(
+            TemplateName.getAsTemplateDecl());
+        AliasTemplate) {
+      LookupTemplateDecl = AliasTemplate;
+      auto UnderlyingType = AliasTemplate->getTemplatedDecl()
+                                ->getUnderlyingType()
+                                .getDesugaredType(Context);
----------------
hokein wrote:

Here we'd like to get the underlying type with all alias stripped. I think both `Desugar` and `Canonical` can achieve the goal here, but `Desugar` seems more explicit.

https://github.com/llvm/llvm-project/pull/77890


More information about the cfe-commits mailing list