https://gcc.gnu.org/g:05ffa494db87bfe3acd717d8cfd3c2c7302a1dbd

commit r16-6935-g05ffa494db87bfe3acd717d8cfd3c2c7302a1dbd
Author: Marek Polacek <[email protected]>
Date:   Tue Jan 20 12:34:17 2026 -0500

    c++/reflection: comment on TARGET_EXPR stripping
    
    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.

Diff:
---
 gcc/cp/reflect.cc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index c1073c59a99c..eae70f86eac9 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;

Reply via email to