@@ -2743,7 +2743,7 @@ Expr *
2743
2743
buildAssociatedConstraints (Sema &SemaRef, FunctionTemplateDecl *F,
2744
2744
TypeAliasTemplateDecl *AliasTemplate,
2745
2745
ArrayRef<DeducedTemplateArgument> DeduceResults,
2746
- unsigned UndeducedTemplateParameterStartIndex ,
2746
+ unsigned FirstUndeducedParamIdx ,
2747
2747
Expr *IsDeducible) {
2748
2748
Expr *RC = F->getTemplateParameters ()->getRequiresClause ();
2749
2749
if (!RC)
@@ -2805,16 +2805,16 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2805
2805
for (unsigned Index = 0 ; Index < DeduceResults.size (); ++Index) {
2806
2806
const auto &D = DeduceResults[Index];
2807
2807
if (D.isNull ()) { // non-deduced template parameters of f
2808
- auto TP = F->getTemplateParameters ()->getParam (Index);
2808
+ NamedDecl* TP = F->getTemplateParameters ()->getParam (Index);
2809
2809
MultiLevelTemplateArgumentList Args;
2810
2810
Args.setKind (TemplateSubstitutionKind::Rewrite);
2811
2811
Args.addOuterTemplateArguments (TemplateArgsForBuildingRC);
2812
2812
// Rebuild the template parameter with updated depth and index.
2813
2813
NamedDecl *NewParam = transformTemplateParameter (
2814
2814
SemaRef, F->getDeclContext (), TP, Args,
2815
- /* NewIndex=*/ UndeducedTemplateParameterStartIndex++ ,
2815
+ /* NewIndex=*/ FirstUndeducedParamIdx ,
2816
2816
getTemplateParameterDepth (TP) + AdjustDepth);
2817
-
2817
+ FirstUndeducedParamIdx += 1 ;
2818
2818
assert (TemplateArgsForBuildingRC[Index].isNull ());
2819
2819
TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument (
2820
2820
Context.getInjectedTemplateArg (NewParam));
@@ -2835,11 +2835,9 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2835
2835
MultiLevelTemplateArgumentList ArgsForBuildingRC;
2836
2836
ArgsForBuildingRC.setKind (clang::TemplateSubstitutionKind::Rewrite);
2837
2837
ArgsForBuildingRC.addOuterTemplateArguments (TemplateArgsForBuildingRC);
2838
- // For 2), if the underlying function template F is nested in a class template
2839
- // (either instantiated from an explicitly-written deduction guide, or
2840
- // synthesized from a constructor), we need the entire template argument list,
2841
- // as the constraint AST in the require-clause of F remains completely
2842
- // uninstantiated.
2838
+ // For 2), if the underlying deduction guide F is nested in a class template,
2839
+ // we need the entire template argument list, as the constraint AST in the
2840
+ // require-clause of F remains completely uninstantiated.
2843
2841
//
2844
2842
// For example:
2845
2843
// template <typename T> // depth 0
@@ -2862,6 +2860,11 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
2862
2860
// We add the outer template arguments which is [int] to the multi-level arg
2863
2861
// list to ensure that the occurrence U in `C<U>` will be replaced with int
2864
2862
// during the substitution.
2863
+ //
2864
+ // NOTE: The underlying deduction guide F is instantiated -- either from an
2865
+ // explicitly-written deduction guide member, or from a constructor.
2866
+ // getInstantiatedFromMemberTemplate() can only handle the former case, so we
2867
+ // check the DeclContext kind.
2865
2868
if (F->getLexicalDeclContext ()->getDeclKind () ==
2866
2869
clang::Decl::ClassTemplateSpecialization) {
2867
2870
auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs (
@@ -3081,7 +3084,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
3081
3084
Context.getInjectedTemplateArg (NewParam));
3082
3085
TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
3083
3086
}
3084
- unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size ();
3087
+ unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size ();
3085
3088
// ...followed by the template parameters of f that were not deduced
3086
3089
// (including their default template arguments)
3087
3090
for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3152,7 +3155,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
3152
3155
SemaRef, AliasTemplate, FPrime->getReturnType (), FPrimeTemplateParams);
3153
3156
Expr *RequiresClause = buildAssociatedConstraints (
3154
3157
SemaRef, F, AliasTemplate, DeduceResults,
3155
- UndeducedTemplateParameterStartIndex , IsDeducible);
3158
+ FirstUndeducedParamIdx , IsDeducible);
3156
3159
3157
3160
auto *FPrimeTemplateParamList = TemplateParameterList::Create (
3158
3161
Context, AliasTemplate->getTemplateParameters ()->getTemplateLoc (),
0 commit comments