This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] rvalue reference implementation for C++0x
- From: "Doug Gregor" <doug dot gregor at gmail dot com>
- To: "Russell Yanofsky" <russ at yanofsky dot org>, "Jason Merrill" <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 25 Apr 2007 10:02:50 -0400
- Subject: Re: [PATCH] rvalue reference implementation for C++0x
- References: <1172076241.31795.32.camel@turtle> <1177478409.29274.8.camel@turtle>
On 4/25/07, Russell Yanofsky <russ@yanofsky.org> wrote:
This is an update of a patch first posted two months ago:
http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01760.html
There was some discussion about it which ended here:
http://gcc.gnu.org/ml/gcc-patches/2007-03/msg01283.html
The updated patch implements rvalue references entirely in the C++ front
end instead of modifying middle end code.
Thanks, Russell!
+/* Return a reference type node referring to TO_TYPE. If RVAL is
+ true, return an rvalue reference type, otherwise return an lvalue
+ reference type. If a type node exists, reuse it, otherwise create
+ a new one. */
+tree
+cp_build_reference_type (tree to_type, bool rval)
+{
+ tree lvalue_ref, t;
+ lvalue_ref = build_reference_type (to_type);
+ if (!rval)
+ return lvalue_ref;
+
+ /* This code to create rvalue reference types is based on and tied
+ to the code creating lvalue reference types in the middle-end
+ functions build_reference_type_for_mode and build_reference_type.
+
+ It works by putting the rvalue reference type nodes after the
+ lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
+ they will effectively be ignored by the middle end. */
+
+ for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
+ if (TYPE_REF_IS_RVALUE (t))
+ return t;
+
+ t = make_node (REFERENCE_TYPE);
+
+ TREE_TYPE (t) = to_type;
+ TYPE_MODE (t) = ptr_mode;
+ TYPE_REF_CAN_ALIAS_ALL (t) = false;
+ TYPE_REF_IS_RVALUE (t) = true;
+ TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
+ TYPE_NEXT_REF_TO (lvalue_ref) = t;
+
+ if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
+ SET_TYPE_STRUCTURAL_EQUALITY (t);
+ else if (TYPE_CANONICAL (to_type) != to_type)
+ TYPE_CANONICAL (t)
+ = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
+
+ layout_type (t);
+
+ return t;
+
+}
Yes, this is definitely the right approach to the rvalue reference
type... and you didn't have to touch the middle-end at all. Great!
Russell, when I applied this patch to the cxx0x-branch, I ran into
three failing test cases that I'd like you to take a look at. They
behave differently under -std=c++0x than under -std=c++98, and I'm not
sure if they're exploiting C++98-specific behavior or whether they are
exposing a bug in the rvalue references implementation. The test cases
are:
g++.dg/init/copy7.C
g++.dg/overload/arg1.C
g++.dg/overload/arg4.C
Would you take a look at these?
- Doug