================ @@ -1061,15 +1061,36 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef, SmallVector<DeducedTemplateArgument> DeduceResults( F->getTemplateParameters()->size()); + // We don't have to deduce against the alias template specialization, + // if the source template is a synthesized alias deduction guide. This allows + // us to utilize the default template arguments from alias declaration. + // + // template <class T> + // using Foo = A<A<T>>; + // + // template <class U = int> + // using Bar = Foo<U>; + // + // In terms of Bar, we want U to appear in the synthesized deduction guide, + // but U would remain undeduced if we deduce against A<T> instead of T. + // Also note that since the deduced results are only used for synthesizing + // template parameters, they should not introduce unintended behavior in + // theory. + ArrayRef<TemplateArgument> Ps = FReturnType->template_arguments(); + if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(F->getTemplatedDecl()); + DG && DG->getSourceDeductionGuideKind() == + CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias) + Ps = F->getInjectedTemplateArgs(Context); ---------------- mizvekov wrote:
>From what I gather about the context of this function, F is always a deduction >guide, so the dyn_cast is superfluous. Also, wouldn't we always be wanting to deduce against the injected template parameters of F anyway, so you could instead just change `FReturnType->template_arguments()` below to `F->getInjectedTemplateArgs(Context)`? And you could then nuke the whole part above about obtaining `FReturnType`, making this fix a simplification overall? https://github.com/llvm/llvm-project/pull/147675 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits