@@ -1956,18 +1956,47 @@ bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
19561956 ParmVarDecl *OldParm) {
19571957 if (SemaRef.CurrentInstantiationScope ->findInstantiationUnsafe (OldParm))
19581958 return false ;
1959- // Make sure the instantiated parameters are owned by the function
1960- // declaration.
1959+ // We're instantiating a function parameter whose associated function template
1960+ // has not been instantiated at this point for constraint evaluation, so make
1961+ // sure the instantiated parameters are owned by a function declaration such
1962+ // that they can be correctly 'captured' in tryCaptureVariable().
19611963 Sema::ContextRAII Context (SemaRef, OldParm->getDeclContext ());
19621964
1963- SmallVector<QualType> PTypes;
1964- Sema::ExtParameterInfoBuilder TInfoBuilder;
1965+ if (!OldParm->isParameterPack ())
1966+ return !TransformFunctionTypeParam (OldParm, /* indexAdjustment=*/ 0 ,
1967+ /* NumExpansions=*/ std::nullopt ,
1968+ /* ExpectParameterPack=*/ false );
1969+
1970+ SmallVector<UnexpandedParameterPack, 2 > Unexpanded;
1971+
1972+ // Find the parameter packs that could be expanded.
1973+ TypeLoc TL = OldParm->getTypeSourceInfo ()->getTypeLoc ();
1974+ PackExpansionTypeLoc ExpansionTL = TL.castAs <PackExpansionTypeLoc>();
1975+ TypeLoc Pattern = ExpansionTL.getPatternLoc ();
1976+ SemaRef.collectUnexpandedParameterPacks (Pattern, Unexpanded);
1977+ assert (!Unexpanded.empty () && " Pack expansion without parameter packs?" );
1978+
1979+ bool ShouldExpand = false ;
1980+ bool RetainExpansion = false ;
1981+ std::optional<unsigned > OrigNumExpansions =
1982+ ExpansionTL.getTypePtr ()->getNumExpansions ();
1983+ std::optional<unsigned > NumExpansions = OrigNumExpansions;
1984+ if (TryExpandParameterPacks (ExpansionTL.getEllipsisLoc (),
1985+ Pattern.getSourceRange (), Unexpanded,
1986+ ShouldExpand, RetainExpansion, NumExpansions))
1987+ return true ;
19651988
1966- return inherited::TransformFunctionTypeParams (
1967- /* Loc=*/ SourceLocation (), /* Params=*/ OldParm, /* ParamTypes=*/ nullptr ,
1968- /* ParamInfos=*/ nullptr , /* PTypes=*/ PTypes, /* PVars=*/ nullptr ,
1969- TInfoBuilder, /* LastParamTransformed=*/ nullptr ,
1970- /* IgnoreParameterIndex=*/ true );
1989+ assert (ShouldExpand && !RetainExpansion &&
1990+ " Shouldn't preserve pack expansion when evaluating constraints" );
1991+ ExpandingFunctionParameterPack (OldParm);
1992+ for (unsigned I = 0 ; I != *NumExpansions; ++I) {
1993+ Sema::ArgumentPackSubstitutionIndexRAII SubstIndex (getSema (), I);
1994+ if (!TransformFunctionTypeParam (OldParm, /* indexAdjustment=*/ 0 ,
1995+ /* NumExpansions=*/ OrigNumExpansions,
1996+ /* ExpectParameterPack=*/ false ))
1997+ return true ;
1998+ }
1999+ return false ;
19712000}
19722001
19732002Decl *TemplateInstantiator::TransformDefinition (SourceLocation Loc, Decl *D) {
0 commit comments