On Fri, Jan 09, 2026 at 12:53:53PM +0800, Jason Merrill wrote:
> On 12/18/25 1:09 AM, Jakub Jelinek wrote:
> > On Tue, Dec 16, 2025 at 10:48:40PM +0700, Jason Merrill wrote:
> > > > +       tree r = finish_compound_literal (type, ctor, 
> > > > tf_warning_or_error,
> > > > +                                         fcl_functional);
> > > > +       if (TREE_CODE (r) == TARGET_EXPR)
> > > 
> > > Let's check SIMPLE_TARGET_EXPR_P in places we're going to strip the
> > > TARGET_EXPR.
> > 
> > diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
> > index 4b2eeb2075f..7d472afd21a 100644
> > --- a/gcc/cp/reflect.cc
> > +++ b/gcc/cp/reflect.cc
> > @@ -593,7 +593,7 @@ get_range_elts (location_t loc, const constexpr_ctx 
> > *ctx, tree call, int n,
> >          TREE_STATIC (ctor) = true;
> >          tree r = finish_compound_literal (type, ctor, tf_warning_or_error,
> >                                            fcl_functional);
> > -       if (TREE_CODE (r) == TARGET_EXPR)
> > +       if (SIMPLE_TARGET_EXPR_P (r))
> >            r = TARGET_EXPR_INITIAL (r);
> >          return r;
> >         }
> > @@ -3001,7 +3001,7 @@ get_vector_of_info_elts (vec<constructor_elt, va_gc> 
> > *elts)
> >       return error_mark_node;
> >     tree r = finish_compound_literal (type, ctor, tf_warning_or_error,
> >                                      fcl_functional);
> > -  if (TREE_CODE (r) == TARGET_EXPR)
> > +  if (SIMPLE_TARGET_EXPR_P (r))
> >       r = TARGET_EXPR_INITIAL (r);
> >     return r;
> >   }
> > 
> > 
> > seems to break pretty much everything unfortunately (151 FAILs compared for
> > make check-g++ RUNTESTFLAGS=dg.exp=reflect/* to 0 before that), e.g.
> 
> Yeah, now I see that change has the same effect as just removing the
> stripping; SIMPLE_TARGET_EXPR_P will always be false because in both places
> TARGET_EXPR_INITIAL is an AGGR_INIT_EXPR with void type.
> 
> And on further poking I see that we're evaluating an AGGR_INIT_EXPR in
> cxx_eval_call_expression, which is already embedded in a TARGET_EXPR, so we
> don't want to add another TARGET_EXPR inside it, so the current stripping is
> correct.
> 
> It might be cleaner to move the stripping to cxx_eval_call_expression rather
> than assume this applies to anything that calls these get_ functions, but I
> suppose that's not necessary.
> 
> Either way, please add a comment.

I'm about to push this patch as obvious:

-- >8 --
As per <https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705305.html>.

gcc/cp/ChangeLog:

        * reflect.cc (get_range_elts): Add comment for TARGET_EXPR stripping.
        (get_vector_of_info_elts): Likewise.
---
 gcc/cp/reflect.cc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index c1073c59a99..eae70f86eac 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -600,6 +600,11 @@ get_range_elts (location_t loc, const constexpr_ctx *ctx, 
tree call, int n,
        TREE_STATIC (ctor) = true;
        tree r = finish_compound_literal (type, ctor, tf_warning_or_error,
                                          fcl_functional);
+       /* Here, we're evaluating an AGGR_INIT_EXPR, which is already
+          embedded in a TARGET_EXPR, so we don't want to add another
+          TARGET_EXPR inside it.  Note that SIMPLE_TARGET_EXPR_P would
+          always be false because the TARGET_EXPR_INITIAL is an
+          AGGR_INIT_EXPR with void type.  */
        if (TREE_CODE (r) == TARGET_EXPR)
          r = TARGET_EXPR_INITIAL (r);
        return r;
@@ -2983,6 +2988,11 @@ get_vector_of_info_elts (vec<constructor_elt, va_gc> 
*elts)
     return error_mark_node;
   tree r = finish_compound_literal (type, ctor, tf_warning_or_error,
                                    fcl_functional);
+  /* Here, we're evaluating an AGGR_INIT_EXPR, which is already
+     embedded in a TARGET_EXPR, so we don't want to add another
+     TARGET_EXPR inside it.  Note that SIMPLE_TARGET_EXPR_P would
+     always be false because the TARGET_EXPR_INITIAL is an
+     AGGR_INIT_EXPR with void type.  */
   if (TREE_CODE (r) == TARGET_EXPR)
     r = TARGET_EXPR_INITIAL (r);
   return r;

base-commit: 358ab6c5ab4d70967ba83a8b5fc426c34d628316
-- 
2.52.0

Reply via email to