@@ -376,12 +376,10 @@ struct ConvertConstructorToDeductionGuideTransform {
376376 if (NestedPattern)
377377 Args.addOuterRetainedLevels (NestedPattern->getTemplateDepth ());
378378 auto [Depth, Index] = getDepthAndIndex (Param);
379- // Depth can still be 0 if FTD belongs to an explicit class template
380- // specialization with an empty template parameter list. In that case,
381- // we don't want the NewDepth to overflow, and it should remain 0.
382- assert (Depth ||
383- cast<ClassTemplateSpecializationDecl>(FTD->getDeclContext ())
384- ->isExplicitSpecialization ());
379+ // Depth can be 0 if FTD belongs to a non-template class/a class
380+ // template specialization with an empty template parameter list. In
381+ // that case, we don't want the NewDepth to overflow, and it should
382+ // remain 0.
385383 NamedDecl *NewParam = transformTemplateParameter (
386384 SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
387385 Depth ? Depth - 1 : 0 );
@@ -970,6 +968,19 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
970968 return {Template, AliasRhsTemplateArgs};
971969}
972970
971+ bool IsNonDeducedArgument (const TemplateArgument &TA) {
972+ // The following cases indicate the template argument is non-deducible:
973+ // 1. The result is null. E.g. When it comes from a default template
974+ // argument that doesn't appear in the alias declaration.
975+ // 2. The template parameter is a pack and that cannot be deduced from
976+ // the arguments within the alias declaration.
977+ // Non-deducible template parameters will persist in the transformed
978+ // deduction guide.
979+ return TA.isNull () ||
980+ (TA.getKind () == TemplateArgument::Pack &&
981+ llvm::any_of (TA.pack_elements (), IsNonDeducedArgument));
982+ }
983+
973984// Build deduction guides for a type alias template from the given underlying
974985// deduction guide F.
975986FunctionTemplateDecl *
@@ -1033,20 +1044,6 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10331044 AliasRhsTemplateArgs, TDeduceInfo, DeduceResults,
10341045 /* NumberOfArgumentsMustMatch=*/ false );
10351046
1036- static std::function<bool (const TemplateArgument &TA)> IsNonDeducedArgument =
1037- [](const TemplateArgument &TA) {
1038- // The following cases indicate the template argument is non-deducible:
1039- // 1. The result is null. E.g. When it comes from a default template
1040- // argument that doesn't appear in the alias declaration.
1041- // 2. The template parameter is a pack and that cannot be deduced from
1042- // the arguments within the alias declaration.
1043- // Non-deducible template parameters will persist in the transformed
1044- // deduction guide.
1045- return TA.isNull () ||
1046- (TA.getKind () == TemplateArgument::Pack &&
1047- llvm::any_of (TA.pack_elements (), IsNonDeducedArgument));
1048- };
1049-
10501047 SmallVector<TemplateArgument> DeducedArgs;
10511048 SmallVector<unsigned > NonDeducedTemplateParamsInFIndex;
10521049 // !!NOTE: DeduceResults respects the sequence of template parameters of
0 commit comments