[clang] [clang] WIP: remove workaround for SubstNonTypeTemplateParmExpr transform (PR #158541)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 15 08:56:41 PDT 2025


================
@@ -2446,40 +2446,14 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
     SubstReplacement = TransformExpr(E->getReplacement());
   if (SubstReplacement.isInvalid())
     return true;
-  QualType SubstType = TransformType(E->getParameterType(getSema().Context));
-  if (SubstType.isNull())
-    return true;
-  // The type may have been previously dependent and not now, which means we
-  // might have to implicit cast the argument to the new type, for example:
-  // template<auto T, decltype(T) U>
-  // concept C = sizeof(U) == 4;
-  // void foo() requires C<2, 'a'> { }
-  // When normalizing foo(), we first form the normalized constraints of C:
-  // AtomicExpr(sizeof(U) == 4,
-  //            U=SubstNonTypeTemplateParmExpr(Param=U,
-  //                                           Expr=DeclRef(U),
-  //                                           Type=decltype(T)))
-  // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to
-  // produce:
-  // AtomicExpr(sizeof(U) == 4,
-  //            U=SubstNonTypeTemplateParmExpr(Param=U,
-  //                                           Expr=ImpCast(
-  //                                               decltype(2),
-  //                                               SubstNTTPE(Param=U, Expr='a',
-  //                                                          Type=char)),
-  //                                           Type=decltype(2)))
-  // The call to CheckTemplateArgument here produces the ImpCast.
-  TemplateArgument SugaredConverted, CanonicalConverted;
-  if (SemaRef
-          .CheckTemplateArgument(E->getParameter(), SubstType,
-                                 SubstReplacement.get(), SugaredConverted,
-                                 CanonicalConverted,
-                                 /*StrictCheck=*/false, Sema::CTAK_Specified)
-          .isInvalid())
+  auto *Param = cast_or_null<NonTypeTemplateParmDecl>(
+      TransformDecl(E->getNameLoc(), E->getParameter()));
----------------
mizvekov wrote:

I don't understand what you mean, if you combine this PR with https://github.com/llvm/llvm-project/pull/141776, before you applied https://github.com/cor3ntin/llvm-project/pull/60, then every test passes, including the one you repeated above.

https://github.com/cor3ntin/llvm-project/pull/60 can't be right, Subst* nodes shouldn't know anything specifically about lambdas.

https://github.com/llvm/llvm-project/pull/158541


More information about the cfe-commits mailing list