C++: member rvalue references are initialized with erroneous copies in constructor initializer list - by to.g

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 681998 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 7/29/2011 4:49:52 AM
Access Restriction Public


Suppose we have a class with a member that holds an rvalue reference, and we want to initialize it in the initializer list of the constructor: 

template< class A >
struct Foo {
	A&& a;
	Foo( A&& a_ ): a( std::forward<A>(a_) ) {}

If the type "A" is int, a local copy of the (referenced int of the) constructor argument "a_" is created and the reference "a" points to this local copy. However, the member "a" really should reference the original value that was referenced by a_.

This leads to problems if the address and lifetime of the reference is important.

Note that the local copy only seems to be created in the constructor's initializer list. For example, "A&& a(std::forward<A>(a_))" does not create a copy. There also seems to be no local copy if the type "A" is user defined (see below).
Sign in to post a comment.
Posted by Microsoft on 8/13/2011 at 6:29 PM
Hi: this bug has been fixed and the fix will show up in a future release of Visual C++.

Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator08 [Feedback Moderator] on 7/31/2011 at 7:50 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 7/29/2011 at 5:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)