@@ -1865,11 +1865,10 @@ namespace {
18651865 Sema::ExtParameterInfoBuilder &PInfos);
18661866
18671867 private:
1868- ExprResult
1869- transformNonTypeTemplateParmRef (Decl *AssociatedDecl,
1870- const NonTypeTemplateParmDecl *parm,
1871- SourceLocation loc, TemplateArgument arg,
1872- std::optional<unsigned > PackIndex);
1868+ ExprResult transformNonTypeTemplateParmRef (
1869+ Decl *AssociatedDecl, const NonTypeTemplateParmDecl *parm,
1870+ SourceLocation loc, TemplateArgument arg,
1871+ std::optional<unsigned > PackIndex, bool Final);
18731872 };
18741873}
18751874
@@ -2140,7 +2139,8 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
21402139 return Arg.getAsExpr ();
21412140 }
21422141
2143- auto [AssociatedDecl, _] = TemplateArgs.getAssociatedDecl (NTTP->getDepth ());
2142+ auto [AssociatedDecl, Final] =
2143+ TemplateArgs.getAssociatedDecl (NTTP->getDepth ());
21442144 std::optional<unsigned > PackIndex;
21452145 if (NTTP->isParameterPack ()) {
21462146 assert (Arg.getKind () == TemplateArgument::Pack &&
@@ -2159,17 +2159,15 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
21592159 QualType ExprType = TargetType.getNonLValueExprType (SemaRef.Context );
21602160 if (TargetType->isRecordType ())
21612161 ExprType.addConst ();
2162- // FIXME: Pass in Final.
21632162 return new (SemaRef.Context ) SubstNonTypeTemplateParmPackExpr (
21642163 ExprType, TargetType->isReferenceType () ? VK_LValue : VK_PRValue,
2165- E->getLocation (), Arg, AssociatedDecl, NTTP->getPosition ());
2164+ E->getLocation (), Arg, AssociatedDecl, NTTP->getPosition (), Final );
21662165 }
21672166 PackIndex = getPackIndex (Arg);
21682167 Arg = getPackSubstitutedTemplateArgument (getSema (), Arg);
21692168 }
2170- // FIXME: Don't put subst node on Final replacement.
21712169 return transformNonTypeTemplateParmRef (AssociatedDecl, NTTP, E->getLocation (),
2172- Arg, PackIndex);
2170+ Arg, PackIndex, Final );
21732171}
21742172
21752173const AnnotateAttr *
@@ -2264,8 +2262,8 @@ TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
22642262
22652263ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef (
22662264 Decl *AssociatedDecl, const NonTypeTemplateParmDecl *parm,
2267- SourceLocation loc, TemplateArgument arg,
2268- std::optional< unsigned > PackIndex ) {
2265+ SourceLocation loc, TemplateArgument arg, std::optional< unsigned > PackIndex,
2266+ bool Final ) {
22692267 ExprResult result;
22702268
22712269 // Determine the substituted parameter type. We can usually infer this from
@@ -2331,10 +2329,9 @@ ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
23312329 return ExprError ();
23322330
23332331 Expr *resultExpr = result.get ();
2334- // FIXME: Don't put subst node on final replacement.
23352332 return new (SemaRef.Context ) SubstNonTypeTemplateParmExpr (
23362333 resultExpr->getType (), resultExpr->getValueKind (), loc, resultExpr,
2337- AssociatedDecl, parm->getIndex (), PackIndex, refParam);
2334+ AssociatedDecl, parm->getIndex (), PackIndex, refParam, Final );
23382335}
23392336
23402337ExprResult
@@ -2347,10 +2344,9 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
23472344
23482345 TemplateArgument Pack = E->getArgumentPack ();
23492346 TemplateArgument Arg = getPackSubstitutedTemplateArgument (getSema (), Pack);
2350- // FIXME: Don't put subst node on final replacement.
23512347 return transformNonTypeTemplateParmRef (
23522348 E->getAssociatedDecl (), E->getParameterPack (),
2353- E->getParameterPackLocation (), Arg, getPackIndex (Pack));
2349+ E->getParameterPackLocation (), Arg, getPackIndex (Pack), E-> getFinal () );
23542350}
23552351
23562352ExprResult
@@ -2392,9 +2388,9 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
23922388 /* PartialOrderingTTP=*/ false , Sema::CTAK_Specified)
23932389 .isInvalid ())
23942390 return true ;
2395- return transformNonTypeTemplateParmRef (E-> getAssociatedDecl (),
2396- E->getParameter (), E->getExprLoc (),
2397- SugaredConverted, E->getPackIndex ());
2391+ return transformNonTypeTemplateParmRef (
2392+ E-> getAssociatedDecl (), E->getParameter (), E->getExprLoc (),
2393+ SugaredConverted, E->getPackIndex (), E-> getFinal ());
23982394}
23992395
24002396ExprResult TemplateInstantiator::RebuildVarDeclRefExpr (ValueDecl *PD,
0 commit comments