]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: fix crash with substitute [PR124204]
authorMarek Polacek <polacek@redhat.com>
Tue, 24 Feb 2026 16:08:55 +0000 (11:08 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 26 Feb 2026 19:32:22 +0000 (14:32 -0500)
Here we crash in implicit_conversion on:

  /* An argument should have gone through convert_from_reference.  */
  gcc_checking_assert (!expr || !TYPE_REF_P (from));

so let's do that.

PR c++/124204

gcc/cp/ChangeLog:

* reflect.cc (eval_can_substitute): Call convert_from_reference.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/substitute5.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/substitute5.C [new file with mode: 0644]

index 871d52a55b119e51a5fc49547d9fffa284464d7b..e90c9e376b1b7eb6d9260dcd506087ffd7786687 100644 (file)
@@ -5318,6 +5318,7 @@ eval_can_substitute (location_t loc, const constexpr_ctx *ctx,
                                "invalid argument to can_substitute",
                                fun, non_constant_p, jump_target);
       a = resolve_nondeduced_context (a, tf_warning_or_error);
+      a = convert_from_reference (a);
       TREE_VEC_ELT (rvec, i) = a;
     }
   if (DECL_TYPE_TEMPLATE_P (r) || DECL_TEMPLATE_TEMPLATE_PARM_P (r))
diff --git a/gcc/testsuite/g++.dg/reflect/substitute5.C b/gcc/testsuite/g++.dg/reflect/substitute5.C
new file mode 100644 (file)
index 0000000..f9af9bf
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/124204
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+template<int>
+using U = void;
+constexpr int v = 0;
+constexpr auto &ref = v;
+constexpr auto result = substitute(^^U, {^^ref});