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.

Jason

Reply via email to