================
@@ -16746,13 +16736,23 @@ ExprResult 
TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
     // specific annotations, such as implicit casts, are discarded. Calling the
     // corresponding sema action is necessary to recover those. Otherwise,
     // equivalency of the result would be lost.
+    //
+    // In unevaluated contexts (e.g. inside decltype), CheckTemplateArgument
+    // forces constant evaluation that is inappropriate and may fail for
+    // valid expressions (e.g. function calls with by-value class parameters).
+    // Since we only need the type in such contexts, we can tolerate the
+    // failure and proceed with the transformed replacement as-is.
     TemplateArgument SugaredConverted, CanonicalConverted;
-    Replacement = SemaRef.CheckTemplateArgument(
+    ExprResult Checked = SemaRef.CheckTemplateArgument(
         Param, ParamType, Replacement.get(), SugaredConverted,
         CanonicalConverted,
         /*StrictCheck=*/false, Sema::CTAK_Specified);
-    if (Replacement.isInvalid())
-      return true;
+    if (Checked.isInvalid()) {
+      if (!SemaRef.isUnevaluatedContext())
+        return true;
+    } else {
+      Replacement = Checked;
+    }
----------------
zyn0217 wrote:

```suggestion
    if (Checked.isInvalid() && !SemaRef.isUnevaluatedContext()) {
        return true;
```


https://github.com/llvm/llvm-project/pull/196791
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to