[clang] [Clang] Transform SubstNonTypeTemplateParmExpr replacements in a constant-evaluated context (PR #196791)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 08:10:16 PDT 2026


================
@@ -16701,6 +16701,19 @@ template <typename Derived>
 ExprResult TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
     SubstNonTypeTemplateParmExpr *E) {
   Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
+
+  // Insert a constant-evaluated context for the transform.
+  // Otherwise, when a normalized constraint places the replacement inside
+  // an unevaluated operand (e.g. decltype), entities it refers to are not
+  // odr-used, and the constant evaluation performed by CheckTemplateArgument
+  // below can spuriously fail for otherwise valid replacements,
+  // e.g. when a call materializes a function parameter of class type whose
+  // special members were never instantiated.
+  EnterExpressionEvaluationContext ConstantEvaluated(
+      SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+      /*LambdaContextDecl=*/nullptr,
+      Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
----------------
wx257osn2 wrote:

So we should be passing `E->getParameter()` instead of `Sema::ReuseLambdaContextDecl`, right?

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


More information about the cfe-commits mailing list