Bug 29939

Summary: Add rvalue references (C++0x)
Product: gcc Reporter: Jeffrey Yasskin <jyasskin>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: doug.gregor, fang, gcc-bugs, hhinnant, pedro.lamarao, s__nakayama
Priority: P5    
Version: 4.3.0   
Target Milestone: 4.3.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2006-11-22 16:43:53

Description Jeffrey Yasskin 2006-11-22 14:18:45 UTC
Rvalue references as described in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html were voted into the C++0x working draft at the 2006 Portland meeting, and I'd like to use them.
Comment 1 David Fang 2006-11-22 15:07:39 UTC
There was some (suspended) discussion about support for rvalue references in PR 24803.  Is there a plan for them somewhere in the pipeline?  
Comment 2 Howard Hinnant 2006-11-22 16:21:35 UTC
If there is a plan, I don't know about it.

Russell Yanofsky has a prototype implementation here:

http://russ.yanofsky.org/rref/

I haven't looked at it enough to know how complete it is.  It was done a couple of years ago.
Comment 4 David Fang 2006-11-29 19:00:34 UTC
Subject: Re:  Add rvalue references (C++0x)

On 29 Nov 2006, hhinnant at apple dot com wrote:

> ------- Comment #3 from hhinnant at apple dot com  2006-11-29 18:36 -------
> Recent work:
>
> http://mndfck.org/~pedro.lamarao/projects/c++0x/
> http://home.twcny.rr.com/hinnant/cpp_extensions/rvalue_ref_test/

Excellent, these tests look like simple examples to learn from, as a
supplement to the technical reports.  Thanks for putting this together.
I'll be following developments and testing from time to time.
I'm highly anticipating this in the upcoming standard.

Fang

Comment 5 Howard Hinnant 2007-02-21 20:17:18 UTC
Russell Yanofsky has submitted a patch implementing N2118:

http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01760.html
Comment 6 David Fang 2007-02-21 20:26:32 UTC
Subject: Re:  Add rvalue references (C++0x)

> ------- Comment #5 from hhinnant at apple dot com  2007-02-21 20:17 -------
> Russell Yanofsky has submitted a patch implementing N2118:
>
> http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01760.html

Thanks for the update.  *excitement*

But shouldn't the patch be dated 2007-02-20? or is it really 2006-02-20?
:)


Fang

Comment 7 dgregor 2007-05-31 01:18:39 UTC
Subject: Bug 29939

Author: dgregor
Date: Thu May 31 01:18:22 2007
New Revision: 125211

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125211
Log:
2007-05-30  Russell Yanofsky <russ@yanofsky.org>
            Douglas Gregor <doug.gregor@gmail.com>
            Pedro Lamarao <pedro.lamarao@mndfck.org>
            Howard Hinnant <howard.hinnant@gmail.com>

	PR c++/7412
	PR c++/29939
        * g++.dg/cpp0x/rv8p.C: New.
        * g++.dg/cpp0x/temp-constructor-bug.C: New.
        * g++.dg/cpp0x/cast-bug.C: New.
        * g++.dg/cpp0x/elision_weak.C: New.
        * g++.dg/cpp0x/collapse-bug.C: New.
        * g++.dg/cpp0x/rv3p.C: New.
        * g++.dg/cpp0x/rv7n.C: New.
        * g++.dg/cpp0x/overload-conv-1.C: New.
        * g++.dg/cpp0x/rv2n.C: New.
        * g++.dg/cpp0x/deduce.C: New.
        * g++.dg/cpp0x/temp-va-arg-bug.C: New.
        * g++.dg/cpp0x/rv6p.C: New.
        * g++.dg/cpp0x/template_deduction.C: New.
        * g++.dg/cpp0x/implicit-copy.C: New.
        * g++.dg/cpp0x/rv1p.C: New.
        * g++.dg/cpp0x/cast.C: New.
        * g++.dg/cpp0x/rv5n.C: New.
        * g++.dg/cpp0x/collapse.C: New.
        * g++.dg/cpp0x/overload-conv-2.C: New.
        * g++.dg/cpp0x/rv4p.C: New.
	* g++.dg/cpp0x/rvo.C: New.
        * g++.dg/cpp0x/iop.C: New.
        * g++.dg/cpp0x/rv3n.C: New.
        * g++.dg/cpp0x/rv7p.C: New.
        * g++.dg/cpp0x/reference_collapsing.C: New.
        * g++.dg/cpp0x/overload.C: New.
        * g++.dg/cpp0x/named.C: New.
        * g++.dg/cpp0x/rv2p.C: New.
        * g++.dg/cpp0x/rv6n.C: New.
        * g++.dg/cpp0x/not_special.C: New.
        * g++.dg/cpp0x/bind.C: New.
        * g++.dg/cpp0x/rv1n.C: New.
        * g++.dg/cpp0x/rv5p.C: New.
        * g++.dg/cpp0x/elision.C: New.
        * g++.dg/cpp0x/named_refs.C: New.
        * g++.dg/cpp0x/unnamed_refs.C: New.
        * g++.dg/cpp0x/rv4n.C: New.
        * g++.dg/cpp0x/elision_neg.C: New.
        * g++.dg/init/copy7.C: Run in C++98 mode.
        * g++.dg/overload/arg1.C: Ditto.
        * g++.dg/overload/arg4.C: Ditto.
	
2007-05-30  Russell Yanofsky <russ@yanofsky.org>
            Douglas Gregor <doug.gregor@gmail.com>
            Pedro Lamarao <pedro.lamarao@mndfck.org>
            Howard Hinnant <howard.hinnant@gmail.com>

	PR c++/7412
	PR c++/29939
	* typeck.c (comptypes): Don't consider rvalue and lvalue
	reference types to be equivalent.
	(check_return_expr): Move from certain lvalues when returning
	them.
	* decl.c (grokdeclarator): Implement reference collapsing.
	(copy_fn_p): Don't consider constructors taking rvalue references
	to be copy constructors.
	(move_fn_p): New.
        * call.c (conversion): New "rvaluedness_matches_p" member.
	(convert_class_to_reference): Require reference type as first
	parameter instead of base type.
	(reference_binding): Add logic to handle rvalue references.
	(implicit_conversion): Update inaccurate comment.
	(convert_like_real): Disable creation of temporaries that are
	impossible to initialize for types with move constructors.
	(build_over_call): Elide move constructors when possible.
	(maybe_handle_implicit_object): Set "rvaluedness_matches_p".
	(maybe_handle_ref_bind): Return conversion instead of type node.
	(compare_ics): Add logic to use "rvaluedness_matches_p" values to
	determine preferred conversion sequences.
	* cp-tree.h (TYPE_REF_IS_RVALUE): New.
	(LOOKUP_PREFER_RVALUE): New.
	(DECL_MOVE_CONSTRUCTOR_P): New.
	(struct cp_declarator): Add "reference" member for reference
	types, with new "rvalue_ref" flag.
	(cp_build_reference_type): Declare.
	(move_fn_p): Declare.
	* error.c (dump_type_prefix): Format rvalue reference types
	correctly in error messages.
	* except.c (build_throw): Move from certain lvalues when
	throwing.
	* mangle.c (write_type): Mangle rvalue references differently
	than regular references.
	* parser.c (make_reference_declarator): Add boolean parameter for
	rvalue references.
	(cp_parser_make_indirect_declarator): New.
	(cp_parser_new_declarator_opt): Call
	cp_parser_make_indirect_declarator. 
	(cp_parser_conversion_declarator_opt): Ditto.
	(cp_parser_declarator): Ditto.
	(cp_parser_ptr_operator): Parse "&&" tokens into rvalue reference
	declarators.
	* pt.c (tsubst): Implement reference collapsing.
	(maybe_adjust_types_for_deduction): Implement special template
	parameter deduction rule for rvalue references.
	(type_unification_real): Update calls to
	maybe_adjust_types_for_deduction.
	(try_one_overload): Ditto.
	(unify_pack_expansion): Ditto.
	* tree.c (lvalue_p_1): Handle rvalue reference types.
	(cp_build_reference_type): New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/bind.C
    trunk/gcc/testsuite/g++.dg/cpp0x/cast-bug.C
    trunk/gcc/testsuite/g++.dg/cpp0x/cast.C
    trunk/gcc/testsuite/g++.dg/cpp0x/collapse-bug.C
    trunk/gcc/testsuite/g++.dg/cpp0x/collapse.C
    trunk/gcc/testsuite/g++.dg/cpp0x/deduce.C
    trunk/gcc/testsuite/g++.dg/cpp0x/elision.C
    trunk/gcc/testsuite/g++.dg/cpp0x/elision_neg.C
    trunk/gcc/testsuite/g++.dg/cpp0x/elision_weak.C
    trunk/gcc/testsuite/g++.dg/cpp0x/implicit-copy.C
    trunk/gcc/testsuite/g++.dg/cpp0x/iop.C
    trunk/gcc/testsuite/g++.dg/cpp0x/named.C
    trunk/gcc/testsuite/g++.dg/cpp0x/named_refs.C
    trunk/gcc/testsuite/g++.dg/cpp0x/not_special.C
    trunk/gcc/testsuite/g++.dg/cpp0x/overload-conv-1.C
    trunk/gcc/testsuite/g++.dg/cpp0x/overload-conv-2.C
    trunk/gcc/testsuite/g++.dg/cpp0x/overload.C
    trunk/gcc/testsuite/g++.dg/cpp0x/reference_collapsing.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv1n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv1p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv2n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv2p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv3n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv3p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv4n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv4p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv5n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv5p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv6n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv6p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv7n.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv7p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv8p.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rvo.C
    trunk/gcc/testsuite/g++.dg/cpp0x/temp-constructor-bug.C
    trunk/gcc/testsuite/g++.dg/cpp0x/temp-va-arg-bug.C
    trunk/gcc/testsuite/g++.dg/cpp0x/template_deduction.C
    trunk/gcc/testsuite/g++.dg/cpp0x/unnamed_refs.C
Modified:
    trunk/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/error.c
    trunk/gcc/cp/except.c
    trunk/gcc/cp/mangle.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/init/copy7.C
    trunk/gcc/testsuite/g++.dg/overload/arg1.C
    trunk/gcc/testsuite/g++.dg/overload/arg4.C

Comment 8 dgregor 2007-05-31 01:28:57 UTC
Rvalue references are now supported on mainline (for 4.3.0) in the experimental C++0x mode.