This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 14230
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Mar 2004 02:09:50 -0800
- Subject: C++ PATCH: PR 14230
- Reply-to: mark at codesourcery dot com
This patch fixes 14230, a problem with reference initialization. We
were failing to use TARGET_EXPRs correctly, as pointed out by Jason in
the PR audit trail. This patch fixes the problem.
Tested on i686-pc-linux-gnu, applied on the mainline and on the 3.4
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-03-09 Mark Mitchell <mark@codesourcery.com>
PR c++/14230
* call.c (initialize_reference): Handle initializers that are
class-member access expressions applies to rvalues.
2004-03-09 Mark Mitchell <mark@codesourcery.com>
PR c++/14230
* g++.dg/init/ref11.C: New test.
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.452.2.9
diff -c -5 -p -r1.452.2.9 call.c
*** cp/call.c 2 Mar 2004 19:57:04 -0000 1.452.2.9
--- cp/call.c 9 Mar 2004 10:02:25 -0000
*************** initialize_reference (tree type, tree ex
*** 6175,6184 ****
--- 6175,6194 ----
/* Create the temporary variable. */
type = TREE_TYPE (expr);
var = make_temporary_var_for_ref_to_temp (decl, type);
layout_decl (var, 0);
+ /* If the rvalue is the result of a function call it will be
+ a TARGET_EXPR. If it is some other construct (such as a
+ member access expression where the underlying object is
+ itself the result of a function call), turn it into a
+ TARGET_EXPR here. It is important that EXPR be a
+ TARGET_EXPR below since otherwise the INIT_EXPR will
+ attempt to make a bitwise copy of EXPR to intialize
+ VAR. */
+ if (TREE_CODE (init) != TARGET_EXPR)
+ expr = get_target_expr (expr);
/* Create the INIT_EXPR that will initialize the temporary
variable. */
init = build (INIT_EXPR, type, var, expr);
if (at_function_scope_p ())
{
Index: testsuite/g++.dg/init/ref11.C
===================================================================
RCS file: testsuite/g++.dg/init/ref11.C
diff -N testsuite/g++.dg/init/ref11.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/ref11.C 9 Mar 2004 10:02:28 -0000
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/14230
+
+ struct A {
+ A ();
+ A (const A&);
+ A& operator= (const A&);
+ };
+
+ struct D {
+ A a;
+ };
+
+ const A& z = D().a;