@@ -996,7 +996,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
996
996
F->getTemplateParameters ()->size ());
997
997
998
998
// 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
1000
1000
// issues for practice cases, we probably need to extend it to continue
1001
1001
// performing deduction for rest of arguments to align with the C++
1002
1002
// standard.
@@ -1053,25 +1053,6 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
1053
1053
TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
1054
1054
}
1055
1055
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
- }
1075
1056
1076
1057
// To form a deduction guide f' from f, we leverage clang's instantiation
1077
1058
// mechanism, we construct a template argument list where the template
@@ -1080,24 +1061,21 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
1080
1061
// f, this ensures all template parameter occurrences are updated
1081
1062
// correctly.
1082
1063
//
1083
- // The template argument list is formed from the `DeducedArgs`, two parts:
1084
- // 1) appeared template parameters of alias: transfrom the deduced
1085
- // template argument;
1086
- // 2) non-deduced template parameters of f: rebuild a
1087
- // template argument;
1064
+ // The template argument list is formed, in order, from
1065
+ // 1) For the template parameters of the alias, the corresponding deduced
1066
+ // template arguments
1067
+ // 2) For the non-deduced template parameters of f. the
1068
+ // (rebuilt) template arguments corresponding.
1088
1069
//
1089
- // 2) has been built already (when rebuilding the new template
1090
- // parameters ), we now perform 1) .
1070
+ // Note: the non-deduced template arguments of `f` might refer to arguments
1071
+ // deduced in 1 ), as in a type constraint .
1091
1072
MultiLevelTemplateArgumentList Args;
1092
1073
Args.setKind (TemplateSubstitutionKind::Rewrite);
1093
1074
Args.addOuterTemplateArguments (TransformedDeducedAliasArgs);
1094
1075
for (unsigned Index = 0 ; Index < DeduceResults.size (); ++Index) {
1095
1076
const auto &D = DeduceResults[Index];
1096
1077
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!" );
1078
+ // 2): Non-deduced template parameters would be substituted later.
1101
1079
continue ;
1102
1080
}
1103
1081
TemplateArgumentLoc Input =
@@ -1110,6 +1088,27 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
1110
1088
}
1111
1089
}
1112
1090
1091
+ // Case 2)
1092
+ // ...followed by the template parameters of f that were not deduced
1093
+ // (including their default template arguments)
1094
+ for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
1095
+ auto *TP = F->getTemplateParameters ()->getParam (FTemplateParamIdx);
1096
+ MultiLevelTemplateArgumentList Args;
1097
+ Args.setKind (TemplateSubstitutionKind::Rewrite);
1098
+ // We take a shortcut here, it is ok to reuse the
1099
+ // TemplateArgsForBuildingFPrime.
1100
+ Args.addOuterTemplateArguments (TemplateArgsForBuildingFPrime);
1101
+ NamedDecl *NewParam = transformTemplateParameter (
1102
+ SemaRef, F->getDeclContext (), TP, Args, FPrimeTemplateParams.size (),
1103
+ getDepthAndIndex (TP).first );
1104
+ FPrimeTemplateParams.push_back (NewParam);
1105
+
1106
+ assert (TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull () &&
1107
+ " The argument must be null before setting" );
1108
+ TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
1109
+ Context.getInjectedTemplateArg (NewParam);
1110
+ }
1111
+
1113
1112
auto *TemplateArgListForBuildingFPrime =
1114
1113
TemplateArgumentList::CreateCopy (Context, TemplateArgsForBuildingFPrime);
1115
1114
// Form the f' by substituting the template arguments into f.
0 commit comments