@@ -1766,70 +1766,6 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
17661766 return Record;
17671767}
17681768
1769- // / Introduce the instantiated function parameters into the local
1770- // / instantiation scope, and set the parameter names to those used
1771- // / in the template.
1772- static bool addInstantiatedParametersToScope (Sema &S, FunctionDecl *Function,
1773- const FunctionDecl *PatternDecl,
1774- LocalInstantiationScope &Scope,
1775- const MultiLevelTemplateArgumentList &TemplateArgs) {
1776- unsigned FParamIdx = 0 ;
1777- for (unsigned I = 0 , N = PatternDecl->getNumParams (); I != N; ++I) {
1778- const ParmVarDecl *PatternParam = PatternDecl->getParamDecl (I);
1779- if (!PatternParam->isParameterPack ()) {
1780- // Simple case: not a parameter pack.
1781- assert (FParamIdx < Function->getNumParams ());
1782- ParmVarDecl *FunctionParam = Function->getParamDecl (FParamIdx);
1783- FunctionParam->setDeclName (PatternParam->getDeclName ());
1784- // If the parameter's type is not dependent, update it to match the type
1785- // in the pattern. They can differ in top-level cv-qualifiers, and we want
1786- // the pattern's type here. If the type is dependent, they can't differ,
1787- // per core issue 1668. Substitute into the type from the pattern, in case
1788- // it's instantiation-dependent.
1789- // FIXME: Updating the type to work around this is at best fragile.
1790- if (!PatternDecl->getType ()->isDependentType ()) {
1791- QualType T = S.SubstType (PatternParam->getType (), TemplateArgs,
1792- FunctionParam->getLocation (),
1793- FunctionParam->getDeclName ());
1794- if (T.isNull ())
1795- return true ;
1796- FunctionParam->setType (T);
1797- }
1798-
1799- Scope.InstantiatedLocal (PatternParam, FunctionParam);
1800- ++FParamIdx;
1801- continue ;
1802- }
1803-
1804- // Expand the parameter pack.
1805- Scope.MakeInstantiatedLocalArgPack (PatternParam);
1806- Optional<unsigned > NumArgumentsInExpansion
1807- = S.getNumArgumentsInExpansion (PatternParam->getType (), TemplateArgs);
1808- if (NumArgumentsInExpansion) {
1809- QualType PatternType =
1810- PatternParam->getType ()->castAs <PackExpansionType>()->getPattern ();
1811- for (unsigned Arg = 0 ; Arg < *NumArgumentsInExpansion; ++Arg) {
1812- ParmVarDecl *FunctionParam = Function->getParamDecl (FParamIdx);
1813- FunctionParam->setDeclName (PatternParam->getDeclName ());
1814- if (!PatternDecl->getType ()->isDependentType ()) {
1815- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex (S, Arg);
1816- QualType T = S.SubstType (PatternType, TemplateArgs,
1817- FunctionParam->getLocation (),
1818- FunctionParam->getDeclName ());
1819- if (T.isNull ())
1820- return true ;
1821- FunctionParam->setType (T);
1822- }
1823-
1824- Scope.InstantiatedLocalPackArg (PatternParam, FunctionParam);
1825- ++FParamIdx;
1826- }
1827- }
1828- }
1829-
1830- return false ;
1831- }
1832-
18331769// / Adjust the given function type for an instantiation of the
18341770// / given declaration, to cope with modifications to the function's type that
18351771// / aren't reflected in the type-source information.
@@ -1912,11 +1848,6 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
19121848 // FIXME: Concepts: Do not substitute into constraint expressions
19131849 Expr *TrailingRequiresClause = D->getTrailingRequiresClause ();
19141850 if (TrailingRequiresClause) {
1915- if (D->isTemplateInstantiation () &&
1916- addInstantiatedParametersToScope (
1917- SemaRef, D, D->getTemplateInstantiationPattern (), Scope,
1918- TemplateArgs))
1919- return nullptr ;
19201851 ExprResult SubstRC = SemaRef.SubstExpr (TrailingRequiresClause,
19211852 TemplateArgs);
19221853 if (SubstRC.isInvalid ())
@@ -4184,6 +4115,70 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D,
41844115 return NewTInfo;
41854116}
41864117
4118+ // / Introduce the instantiated function parameters into the local
4119+ // / instantiation scope, and set the parameter names to those used
4120+ // / in the template.
4121+ static bool addInstantiatedParametersToScope (Sema &S, FunctionDecl *Function,
4122+ const FunctionDecl *PatternDecl,
4123+ LocalInstantiationScope &Scope,
4124+ const MultiLevelTemplateArgumentList &TemplateArgs) {
4125+ unsigned FParamIdx = 0 ;
4126+ for (unsigned I = 0 , N = PatternDecl->getNumParams (); I != N; ++I) {
4127+ const ParmVarDecl *PatternParam = PatternDecl->getParamDecl (I);
4128+ if (!PatternParam->isParameterPack ()) {
4129+ // Simple case: not a parameter pack.
4130+ assert (FParamIdx < Function->getNumParams ());
4131+ ParmVarDecl *FunctionParam = Function->getParamDecl (FParamIdx);
4132+ FunctionParam->setDeclName (PatternParam->getDeclName ());
4133+ // If the parameter's type is not dependent, update it to match the type
4134+ // in the pattern. They can differ in top-level cv-qualifiers, and we want
4135+ // the pattern's type here. If the type is dependent, they can't differ,
4136+ // per core issue 1668. Substitute into the type from the pattern, in case
4137+ // it's instantiation-dependent.
4138+ // FIXME: Updating the type to work around this is at best fragile.
4139+ if (!PatternDecl->getType ()->isDependentType ()) {
4140+ QualType T = S.SubstType (PatternParam->getType (), TemplateArgs,
4141+ FunctionParam->getLocation (),
4142+ FunctionParam->getDeclName ());
4143+ if (T.isNull ())
4144+ return true ;
4145+ FunctionParam->setType (T);
4146+ }
4147+
4148+ Scope.InstantiatedLocal (PatternParam, FunctionParam);
4149+ ++FParamIdx;
4150+ continue ;
4151+ }
4152+
4153+ // Expand the parameter pack.
4154+ Scope.MakeInstantiatedLocalArgPack (PatternParam);
4155+ Optional<unsigned > NumArgumentsInExpansion
4156+ = S.getNumArgumentsInExpansion (PatternParam->getType (), TemplateArgs);
4157+ if (NumArgumentsInExpansion) {
4158+ QualType PatternType =
4159+ PatternParam->getType ()->castAs <PackExpansionType>()->getPattern ();
4160+ for (unsigned Arg = 0 ; Arg < *NumArgumentsInExpansion; ++Arg) {
4161+ ParmVarDecl *FunctionParam = Function->getParamDecl (FParamIdx);
4162+ FunctionParam->setDeclName (PatternParam->getDeclName ());
4163+ if (!PatternDecl->getType ()->isDependentType ()) {
4164+ Sema::ArgumentPackSubstitutionIndexRAII SubstIndex (S, Arg);
4165+ QualType T = S.SubstType (PatternType, TemplateArgs,
4166+ FunctionParam->getLocation (),
4167+ FunctionParam->getDeclName ());
4168+ if (T.isNull ())
4169+ return true ;
4170+ FunctionParam->setType (T);
4171+ }
4172+
4173+ Scope.InstantiatedLocalPackArg (PatternParam, FunctionParam);
4174+ ++FParamIdx;
4175+ }
4176+ }
4177+ }
4178+
4179+ return false ;
4180+ }
4181+
41874182void Sema::InstantiateExceptionSpec (SourceLocation PointOfInstantiation,
41884183 FunctionDecl *Decl) {
41894184 const FunctionProtoType *Proto = Decl->getType ()->castAs <FunctionProtoType>();
0 commit comments