@@ -996,7 +996,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
996996 F->getTemplateParameters ()->size ());
997997
998998 // FIXME: DeduceTemplateArguments stops immediately at the first
999- // non-deducible template argument. However, this doesn't seem to casue
999+ // non-deducible template argument. However, this doesn't seem to cause
10001000 // issues for practice cases, we probably need to extend it to continue
10011001 // performing deduction for rest of arguments to align with the C++
10021002 // standard.
@@ -1053,25 +1053,6 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10531053 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
10541054 }
10551055 unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size ();
1056- // ...followed by the template parameters of f that were not deduced
1057- // (including their default template arguments)
1058- for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
1059- auto *TP = F->getTemplateParameters ()->getParam (FTemplateParamIdx);
1060- MultiLevelTemplateArgumentList Args;
1061- Args.setKind (TemplateSubstitutionKind::Rewrite);
1062- // We take a shortcut here, it is ok to reuse the
1063- // TemplateArgsForBuildingFPrime.
1064- Args.addOuterTemplateArguments (TemplateArgsForBuildingFPrime);
1065- NamedDecl *NewParam = transformTemplateParameter (
1066- SemaRef, F->getDeclContext (), TP, Args, FPrimeTemplateParams.size (),
1067- getDepthAndIndex (TP).first );
1068- FPrimeTemplateParams.push_back (NewParam);
1069-
1070- assert (TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull () &&
1071- " The argument must be null before setting" );
1072- TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
1073- Context.getInjectedTemplateArg (NewParam);
1074- }
10751056
10761057 // To form a deduction guide f' from f, we leverage clang's instantiation
10771058 // mechanism, we construct a template argument list where the template
@@ -1086,18 +1067,14 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10861067 // 2) non-deduced template parameters of f: rebuild a
10871068 // template argument;
10881069 //
1089- // 2) has been built already (when rebuilding the new template
1090- // parameters), we now perform 1).
1070+ // We now perform 1), as case 2) might refer to substituted 1).
10911071 MultiLevelTemplateArgumentList Args;
10921072 Args.setKind (TemplateSubstitutionKind::Rewrite);
10931073 Args.addOuterTemplateArguments (TransformedDeducedAliasArgs);
10941074 for (unsigned Index = 0 ; Index < DeduceResults.size (); ++Index) {
10951075 const auto &D = DeduceResults[Index];
10961076 if (D.isNull ()) {
1097- // 2): Non-deduced template parameter has been built already.
1098- assert (!TemplateArgsForBuildingFPrime[Index].isNull () &&
1099- " template arguments for non-deduced template parameters should "
1100- " be been set!" );
1077+ // 2): Non-deduced template parameters would be substituted later.
11011078 continue ;
11021079 }
11031080 TemplateArgumentLoc Input =
@@ -1110,6 +1087,27 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
11101087 }
11111088 }
11121089
1090+ // Case 2)
1091+ // ...followed by the template parameters of f that were not deduced
1092+ // (including their default template arguments)
1093+ for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
1094+ auto *TP = F->getTemplateParameters ()->getParam (FTemplateParamIdx);
1095+ MultiLevelTemplateArgumentList Args;
1096+ Args.setKind (TemplateSubstitutionKind::Rewrite);
1097+ // We take a shortcut here, it is ok to reuse the
1098+ // TemplateArgsForBuildingFPrime.
1099+ Args.addOuterTemplateArguments (TemplateArgsForBuildingFPrime);
1100+ NamedDecl *NewParam = transformTemplateParameter (
1101+ SemaRef, F->getDeclContext (), TP, Args, FPrimeTemplateParams.size (),
1102+ getDepthAndIndex (TP).first );
1103+ FPrimeTemplateParams.push_back (NewParam);
1104+
1105+ assert (TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull () &&
1106+ " The argument must be null before setting" );
1107+ TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
1108+ Context.getInjectedTemplateArg (NewParam);
1109+ }
1110+
11131111 auto *TemplateArgListForBuildingFPrime =
11141112 TemplateArgumentList::CreateCopy (Context, TemplateArgsForBuildingFPrime);
11151113 // Form the f' by substituting the template arguments into f.
0 commit comments