This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to build_target_expr_with_type for 11878


Like all the cp_expr_size aborts, this one is a case of the compiler trying
to do a bitwise copy of a type that must always go through a copy
constructor.  In this case, stabilize_expr was calling get_target_expr to
make an expression persistent.  The expression in question, B<A>().t, is an
rvalue but not a temporary, so we need to build up a temporary copy.

Fixed thus.  The COND_EXPR check is to avoid extra copies on
g++.jason/temporary8.C.

Tested x86_64-pc-linux-gnu, applied to trunk and 3.3.

Test in g++.dg/init/copy6.C.

2003-10-14  Jason Merrill  <jason@redhat.com>

	PR c++/11878
	* tree.c (stabilize_expr): Call force_rvalue before building a
	TARGET_EXPR.

*** tree.c.~1~	2003-10-13 18:02:41.000000000 -0400
--- tree.c	2003-10-14 15:54:51.000000000 -0400
*************** build_target_expr_with_type (init, type)
*** 357,362 ****
--- 357,368 ----
  
    if (TREE_CODE (init) == TARGET_EXPR)
      return init;
+   else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
+ 	   && TREE_CODE (init) != COND_EXPR)
+     /* We need to build up a copy constructor call.  COND_EXPR is a special
+        case because we already have copies on the arms and we don't want
+        another one here.  */
+     return force_rvalue (init);
  
    slot = build (VAR_DECL, type);
    DECL_ARTIFICIAL (slot) = 1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]