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).
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...