https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54319

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is the code in call.c that makes a difference:
      if (is_really_empty_class (type, /*ignore_vptr*/true))
        {
          /* Avoid copying empty classes.  */
          val = build2 (COMPOUND_EXPR, type, arg, to);
          suppress_warning (val, OPT_Wunused);
        }
      else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
        {
          if (is_std_init_list (type)
              && conv_binds_ref_to_prvalue (convs[1]))
            warning_at (loc, OPT_Winit_list_lifetime,
                        "assignment from temporary %<initializer_list%> does "
                        "not extend the lifetime of the underlying array");
          arg = cp_build_fold_indirect_ref (arg);
          val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
        }
      else
        {
          /* We must only copy the non-tail padding parts.  */
          tree arg0, arg2, t;
          tree array_type, alias_set;

          arg2 = TYPE_SIZE_UNIT (as_base);
          to = cp_stabilize_reference (to);
          arg0 = cp_build_addr_expr (to, complain);

          array_type = build_array_type (unsigned_char_type_node,
                                         build_index_type
                                           (size_binop (MINUS_EXPR,
                                                        arg2, size_int (1))));
          alias_set = build_int_cst (build_pointer_type (type), 0);
          t = build2 (MODIFY_EXPR, void_type_node,
                      build2 (MEM_REF, array_type, arg0, alias_set),
                      build2 (MEM_REF, array_type, arg, alias_set));
          val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
          suppress_warning (val, OPT_Wunused);
        }

if we do the middle one only, we get the correct type.
I won't be able to debug this any further. But I suspect because we are
lowering the AST too early, we don't do the correct type dealing here due to
the COMPOUND_EXPR.

Reply via email to