Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 681998
Opened: 7/29/2011 4:49:52 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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).
Details
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++.

Thanks
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)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
test3.cpp 7/29/2011 1 KB