@@ -2268,15 +2268,6 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
22682268 // We're rewriting the template parameter as a reference to another
22692269 // template parameter.
22702270 Arg = getTemplateArgumentPackPatternForRewrite (Arg);
2271- if (Arg.getKind () != TemplateArgument::Expression) {
2272- assert (SemaRef.inParameterMappingSubstitution () ||
2273- SemaRef.inConstraintSubstitution ());
2274- ExprResult Expr = SemaRef.BuildExpressionFromNonTypeTemplateArgument (
2275- Arg, E->getLocation ());
2276- if (Expr.isInvalid ())
2277- return E;
2278- Arg = TemplateArgument (Expr.get (), /* IsCanonical=*/ false );
2279- }
22802271 assert (Arg.getKind () == TemplateArgument::Expression &&
22812272 " unexpected nontype template argument kind in template rewrite" );
22822273 // FIXME: This can lead to the same subexpression appearing multiple times
@@ -2498,11 +2489,21 @@ ExprResult
24982489TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr (
24992490 SubstNonTypeTemplateParmExpr *E) {
25002491 ExprResult SubstReplacement = E->getReplacement ();
2492+ QualType ParamType = E->getParameterType (getSema ().Context );
2493+ bool WasDependentLambda = false ;
2494+ if (auto *RT = dyn_cast<RecordType>(ParamType);
2495+ RT && RT->getAsCXXRecordDecl ())
2496+ WasDependentLambda = RT->getAsCXXRecordDecl ()->isDependentLambda ();
25012497 if (!isa<ConstantExpr>(SubstReplacement.get ()))
25022498 SubstReplacement = TransformExpr (E->getReplacement ());
25032499 if (SubstReplacement.isInvalid ())
25042500 return true ;
2505- QualType SubstType = TransformType (E->getParameterType (getSema ().Context ));
2501+ // FIXME: This transform cannot find the instantiated lambda declaration
2502+ // because lambdas are instantiated in a unique scope.
2503+ QualType SubstType =
2504+ WasDependentLambda
2505+ ? SubstReplacement.get ()->getType ().getUnqualifiedType ()
2506+ : TransformType (ParamType);
25062507 if (SubstType.isNull ())
25072508 return true ;
25082509 // The type may have been previously dependent and not now, which means we
0 commit comments