@@ -949,7 +949,7 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
949949 ReturnType = SemaRef.SubstType (
950950 ReturnType, Args, AliasTemplate->getLocation (),
951951 Context.DeclarationNames .getCXXDeductionGuideName (AliasTemplate));
952- };
952+ }
953953
954954 SmallVector<TypeSourceInfo *> IsDeducibleTypeTraitArgs = {
955955 Context.getTrivialTypeSourceInfo (
@@ -981,7 +981,8 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
981981 // template<typename T>
982982 // using AliasFoo1 = Foo<T>; // a class/type alias template specialization
983983 Template = TST->getTemplateName ().getAsTemplateDecl ();
984- AliasRhsTemplateArgs = TST->template_arguments ();
984+ AliasRhsTemplateArgs =
985+ TST->getAsNonAliasTemplateSpecializationType ()->template_arguments ();
985986 } else if (const auto *RT = RhsType->getAs <RecordType>()) {
986987 // Cases where template arguments in the RHS of the alias are not
987988 // dependent. e.g.
@@ -1025,6 +1026,24 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10251026 auto [Template, AliasRhsTemplateArgs] =
10261027 getRHSTemplateDeclAndArgs (SemaRef, AliasTemplate);
10271028
1029+ // We need both types desugared, before we continue to perform type deduction.
1030+ // The intent is to get the template argument list 'matched', e.g. in the
1031+ // following case:
1032+ //
1033+ //
1034+ // template <class T>
1035+ // struct A {};
1036+ // template <class T>
1037+ // using Foo = A<A<T>>;
1038+ // template <class U = int>
1039+ // using Bar = Foo<U>;
1040+ //
1041+ // In terms of Bar, we want U (which has the default argument) to appear in
1042+ // the synthesized deduction guide, but U would remain undeduced if we deduced
1043+ // A<A<T>> using Foo<U> directly.
1044+ //
1045+ // Instead, we need to canonicalize both against A, i.e. A<A<T>> and A<A<U>>,
1046+ // such that T can be deduced as U.
10281047 auto RType = F->getTemplatedDecl ()->getReturnType ();
10291048 // The (trailing) return type of the deduction guide.
10301049 const TemplateSpecializationType *FReturnType =
@@ -1034,7 +1053,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10341053 FReturnType = InjectedCNT->getInjectedTST ();
10351054 else if (const auto *ET = RType->getAs <ElaboratedType>())
10361055 // explicit deduction guide.
1037- FReturnType = ET->getNamedType ()->getAs <TemplateSpecializationType> ();
1056+ FReturnType = ET->getNamedType ()->getAsNonAliasTemplateSpecializationType ();
10381057 assert (FReturnType && " expected to see a return type" );
10391058 // Deduce template arguments of the deduction guide f from the RHS of
10401059 // the alias.
0 commit comments