------- Comment #10 from matz at gcc dot gnu dot org  2008-02-02 17:47 -------
A TARGET_EXPR has the following semantics:
(1) If it's a RHS of a MODIFY_STMT (or similar), i.e.:
       lhs = TARGET_EXPR<slot, init, cleanup>
    this is (for gimplifying) the same as
       lhs = init
    except when TREE_TYPE(init) is void, in that case the init tree is
    expected to magically set 'slot' when evaluated.
(2) If it's not the RHS of something, i.e. in a toplevel stmt for instance,
    then this is equivalent to:
       slot = init
    (again, except when 'init' has void type).

Let's ignore the case that 'init' has void type, then 'init' is an expression,
and the semantics of TARGET_EXPR are the same as
    temp = init

This is only valid when
  useless_type_conversion(TREE_TYPE(temp), TREE_TYPE(init)) .
Hence I think for all TARGET_EXPRs created, for which init hasn't void type,
the above predicate has to hold.  I think this is best ensured in the lowest
functions which create TARGET_EXPR, not in the high-level users.

Hence I think the safest would be to modify build_target_expr directly,
with something like this:

Index: cp/tree.c
===================================================================
--- cp/tree.c   (Revision 132064)
+++ cp/tree.c   (Arbeitskopie)
@@ -259,6 +259,11 @@ build_target_expr (tree decl, tree value
 {
   tree t;

+  if (!VOID_TYPE_P (TREE_TYPE (value))
+      && TREE_TYPE (decl) != TREE_TYPE (value)
+      && !useless_type_conversion_p (TREE_TYPE (decl), TREE_TYPE (value)))
+    value = fold_convert (TREE_TYPE (decl), value);
+
   t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value,
              cxx_maybe_build_cleanup (decl), NULL_TREE);
   /* We always set TREE_SIDE_EFFECTS so that expand_expr does not


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35056

Reply via email to