On Wed, Feb 25, 2026 at 11:13:50AM +0900, Jason Merrill wrote:
> On 2/25/26 1:40 AM, Marek Polacek wrote:
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> >
> > -- >8 --
> > 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.
>
> OK, but I expect more places that use REFLECT_EXPR_HANDLE directly will need
> this as well, and I wonder about using a common function instead, like
> splice(). But I see that splice() doesn't currently do this either, and I
> wonder why that isn't breaking?
splice doesn't call convert_from_reference, true, but we let
cp_parser_splice_expression -> finish_id_expression do that.
> > gcc/testsuite/ChangeLog:
> >
> > * g++.dg/reflect/substitute5.C: New test.
> > ---
> > gcc/cp/reflect.cc | 1 +
> > gcc/testsuite/g++.dg/reflect/substitute5.C | 11 +++++++++++
> > 2 files changed, 12 insertions(+)
> > create mode 100644 gcc/testsuite/g++.dg/reflect/substitute5.C
> >
> > diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
> > index 522b7c06a29..7f23784be5d 100644
> > --- a/gcc/cp/reflect.cc
> > +++ b/gcc/cp/reflect.cc
> > @@ -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
> > index 00000000000..f9af9bf5f46
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/reflect/substitute5.C
> > @@ -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});
> >
> > base-commit: 4cd4ec9bd3de347fbd112d2762e05a607243253c
>
Marek