@@ -2779,7 +2779,7 @@ Expr *
2779
2779
buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2780
2780
TypeAliasTemplateDecl *AliasTemplate,
2781
2781
ArrayRef<DeducedTemplateArgument> DeduceResults,
2782
- unsigned UndeducedTemplateParameterStartIndex ,
2782
+ unsigned FirstUndeducedParamIdx ,
2783
2783
Expr *IsDeducible) {
2784
2784
Expr *RC = F->getTemplateParameters()->getRequiresClause();
2785
2785
if (!RC)
@@ -2841,16 +2841,16 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2841
2841
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
2842
2842
const auto &D = DeduceResults[Index];
2843
2843
if (D.isNull()) { // non-deduced template parameters of f
2844
- auto TP = F->getTemplateParameters()->getParam(Index);
2844
+ NamedDecl* TP = F->getTemplateParameters()->getParam(Index);
2845
2845
MultiLevelTemplateArgumentList Args;
2846
2846
Args.setKind(TemplateSubstitutionKind::Rewrite);
2847
2847
Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
2848
2848
// Rebuild the template parameter with updated depth and index.
2849
2849
NamedDecl *NewParam = transformTemplateParameter(
2850
2850
SemaRef, F->getDeclContext(), TP, Args,
2851
- /*NewIndex=*/UndeducedTemplateParameterStartIndex++ ,
2851
+ /*NewIndex=*/FirstUndeducedParamIdx ,
2852
2852
getTemplateParameterDepth(TP) + AdjustDepth);
2853
-
2853
+ FirstUndeducedParamIdx += 1;
2854
2854
assert(TemplateArgsForBuildingRC[Index].isNull());
2855
2855
TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument(
2856
2856
Context.getInjectedTemplateArg(NewParam));
@@ -2871,11 +2871,9 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2871
2871
MultiLevelTemplateArgumentList ArgsForBuildingRC;
2872
2872
ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
2873
2873
ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
2874
- // For 2), if the underlying function template F is nested in a class template
2875
- // (either instantiated from an explicitly-written deduction guide, or
2876
- // synthesized from a constructor), we need the entire template argument list,
2877
- // as the constraint AST in the require-clause of F remains completely
2878
- // uninstantiated.
2874
+ // For 2), if the underlying deduction guide F is nested in a class template,
2875
+ // we need the entire template argument list, as the constraint AST in the
2876
+ // require-clause of F remains completely uninstantiated.
2879
2877
//
2880
2878
// For example:
2881
2879
// template <typename T> // depth 0
@@ -2898,6 +2896,11 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2898
2896
// We add the outer template arguments which is [int] to the multi-level arg
2899
2897
// list to ensure that the occurrence U in `C<U>` will be replaced with int
2900
2898
// during the substitution.
2899
+ //
2900
+ // NOTE: The underlying deduction guide F is instantiated -- either from an
2901
+ // explicitly-written deduction guide member, or from a constructor.
2902
+ // getInstantiatedFromMemberTemplate() can only handle the former case, so we
2903
+ // check the DeclContext kind.
2901
2904
if (F->getLexicalDeclContext()->getDeclKind() ==
2902
2905
clang::Decl::ClassTemplateSpecialization) {
2903
2906
auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
@@ -3117,7 +3120,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
3117
3120
Context.getInjectedTemplateArg(NewParam));
3118
3121
TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
3119
3122
}
3120
- unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();
3123
+ unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
3121
3124
// ...followed by the template parameters of f that were not deduced
3122
3125
// (including their default template arguments)
3123
3126
for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3188,7 +3191,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
3188
3191
SemaRef, AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
3189
3192
Expr *RequiresClause = buildAssociatedConstraints(
3190
3193
SemaRef, F, AliasTemplate, DeduceResults,
3191
- UndeducedTemplateParameterStartIndex , IsDeducible);
3194
+ FirstUndeducedParamIdx , IsDeducible);
3192
3195
3193
3196
auto *FPrimeTemplateParamList = TemplateParameterList::Create(
3194
3197
Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
0 commit comments