@@ -623,10 +623,15 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
623623 Inst.DeductionInfo = DeductionInfo;
624624 Inst.InstantiationRange = InstantiationRange;
625625 Inst.InConstraintSubstitution =
626- Inst.Kind == CodeSynthesisContext::ConstraintSubstitution;
627- if (!SemaRef.CodeSynthesisContexts .empty ())
626+ Inst.Kind == CodeSynthesisContext::ConstraintsCheck;
627+ Inst.InParameterMappingSubstitution =
628+ Inst.Kind == CodeSynthesisContext::ParameterMappingSubstitution;
629+ if (!SemaRef.CodeSynthesisContexts .empty ()) {
628630 Inst.InConstraintSubstitution |=
629631 SemaRef.CodeSynthesisContexts .back ().InConstraintSubstitution ;
632+ Inst.InParameterMappingSubstitution |=
633+ SemaRef.CodeSynthesisContexts .back ().InParameterMappingSubstitution ;
634+ }
630635
631636 SemaRef.pushCodeSynthesisContext (Inst);
632637
@@ -2225,6 +2230,14 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
22252230 // We're rewriting the template parameter as a reference to another
22262231 // template parameter.
22272232 Arg = getTemplateArgumentPackPatternForRewrite (Arg);
2233+ if (Arg.getKind () != TemplateArgument::Expression) {
2234+ assert (SemaRef.inParameterMappingSubstitution ());
2235+ // FIXME: SourceLocation()?
2236+ ExprResult E = SemaRef.BuildExpressionFromNonTypeTemplateArgument (Arg, SourceLocation ());
2237+ if (E.isInvalid ())
2238+ return E;
2239+ Arg = TemplateArgument (E.get (), /* IsCanonical=*/ false );
2240+ }
22282241 assert (Arg.getKind () == TemplateArgument::Expression &&
22292242 " unexpected nontype template argument kind in template rewrite" );
22302243 // FIXME: This can lead to the same subexpression appearing multiple times
@@ -3249,7 +3262,7 @@ bool Sema::SubstTypeConstraint(
32493262 const ASTTemplateArgumentListInfo *TemplArgInfo =
32503263 TC->getTemplateArgsAsWritten ();
32513264
3252- if (!EvaluateConstraints) {
3265+ if (!EvaluateConstraints && ! inParameterMappingSubstitution () ) {
32533266 UnsignedOrNone Index = TC->getArgPackSubstIndex ();
32543267 if (!Index)
32553268 Index = SemaRef.ArgPackSubstIndex ;
0 commit comments