@@ -2441,45 +2441,17 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
24412441ExprResult
24422442TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr (
24432443 SubstNonTypeTemplateParmExpr *E) {
2444- ExprResult SubstReplacement = E->getReplacement ();
2445- if (!isa<ConstantExpr>(SubstReplacement.get ()))
2446- SubstReplacement = TransformExpr (E->getReplacement ());
2444+ ExprResult SubstReplacement = TransformExpr (E->getReplacement ());
24472445 if (SubstReplacement.isInvalid ())
24482446 return true ;
2449- QualType SubstType = TransformType (E->getParameterType (getSema ().Context ));
2450- if (SubstType.isNull ())
2451- return true ;
2452- // The type may have been previously dependent and not now, which means we
2453- // might have to implicit cast the argument to the new type, for example:
2454- // template<auto T, decltype(T) U>
2455- // concept C = sizeof(U) == 4;
2456- // void foo() requires C<2, 'a'> { }
2457- // When normalizing foo(), we first form the normalized constraints of C:
2458- // AtomicExpr(sizeof(U) == 4,
2459- // U=SubstNonTypeTemplateParmExpr(Param=U,
2460- // Expr=DeclRef(U),
2461- // Type=decltype(T)))
2462- // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to
2463- // produce:
2464- // AtomicExpr(sizeof(U) == 4,
2465- // U=SubstNonTypeTemplateParmExpr(Param=U,
2466- // Expr=ImpCast(
2467- // decltype(2),
2468- // SubstNTTPE(Param=U, Expr='a',
2469- // Type=char)),
2470- // Type=decltype(2)))
2471- // The call to CheckTemplateArgument here produces the ImpCast.
2472- TemplateArgument SugaredConverted, CanonicalConverted;
2473- if (SemaRef
2474- .CheckTemplateArgument (E->getParameter (), SubstType,
2475- SubstReplacement.get (), SugaredConverted,
2476- CanonicalConverted,
2477- /* StrictCheck=*/ false , Sema::CTAK_Specified)
2478- .isInvalid ())
2447+ auto *Param = cast_or_null<NonTypeTemplateParmDecl>(
2448+ TransformDecl (E->getNameLoc (), E->getParameter ()));
2449+ if (!Param)
24792450 return true ;
24802451 return transformNonTypeTemplateParmRef (
2481- E->getAssociatedDecl (), E->getParameter (), E->getExprLoc (),
2482- SugaredConverted, E->getPackIndex (), E->getFinal ());
2452+ E->getAssociatedDecl (), Param, E->getExprLoc (),
2453+ TemplateArgument (SubstReplacement.get (), /* IsCanonical=*/ false ),
2454+ E->getPackIndex (), E->getFinal ());
24832455}
24842456
24852457ExprResult TemplateInstantiator::RebuildVarDeclRefExpr (ValueDecl *PD,
0 commit comments