[PATCH] rvalue reference implementation for C++0x

Russell Yanofsky russ@yanofsky.org
Sun Mar 11 10:54:00 GMT 2007


On Sat, 2007-03-10 at 23:16 -0800, Andrew Pinski wrote:
> On 3/10/07, Russell Yanofsky <russ@yanofsky.org> wrote:
> > L-value references are already part of middle end code and I don't see
> > why r-value references should be different. Are there actually other
> > languages besides C++ which use REFERENCE_TYPE nodes?
> 
> Yes, the fortran front-end uses REFERENCE_TYPE for all argument types
> as in Fortran every function argument is passed via reference and not
> via value.  The main reason why Fortran uses it is so they get the
> correct debugging information for arguments.
> 
> Ada also uses REFERENCE_TYPE but I don't know what for.  You know if
> you did a quick search for build_reference_type in */*.c you would
> have found these uses :).

Well yeah. And if I would have tried to change the signature of the
existing build_reference_* functions, I certainly would have bumped into
them. I actually think it's pretty neat how the same concept has been
reused across the different language implementations. And I can see now
how it is a little presumptuous for me to add a C++ specific flag into
this shared type node. This doesn't change the fact that for the
implementation of the rvalue reference feature, it is much cleaner to be
able to distinguish between different kinds of REFERENCE_TYPE nodes by
looking at the nodes themselves, instead of keeping information in some
external data structure or encoding it in the ordering of a linked list.

Maybe the thing to do here is to generalize the concept of there being
different kinds of reference types. Doing this would be as simple as
renaming the TYPE_REF_IS_RVALUE macro to TYPE_REF_KIND. That way, any of
the front ends would be able to easily distinguish between different
kinds of references. The C++ front end would use this to distinguish
between r- and l-value references, and if they find new uses for
REFERENCE_TYPE nodes in the Fortran or Ada front ends, being able to
distinguish between different kinds of reference types could prove
useful there as well.

> In fact there are some people who want to get rid of REFERENCE_TYPE
> and make it a flag off of POINTER_TYPE.

You could count me among them, though I think the benefits would be
pretty minimal.

-- 
-  Russell Yanofsky (PGP ID: 0x5FAA0216)
-  http://russ.yanofsky.org/
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070311/4e5a6526/attachment.sig>


More information about the Gcc-patches mailing list