[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#478734: g++-4.2: refuses to compile valid C++ syntax



On Thu, May 01, 2008 at 10:39:24AM -0500, Jason Kraftcheck wrote:
> Daniel Jacobowitz wrote:
>> On Wed, Apr 30, 2008 at 05:51:32PM -0500, Jason Kraftcheck wrote:
>>> Why can't I take a reference to an rvalue?
>>
>> Because you can't modify rvalues.  This is the definition of the C++
>> language.  The next major revision of C++ will have T &&rref, the two
>> ampersands declaring an rvalue reference instead of the normal lvalue
>> kind.
>
> Are you certain that the temporary created by invoking the copy  
> constructor is an rvalue?  If so, then why does the following syntax work?
>
> std::vector<int> v;
> std::vector<int> w( std:vector<int>(v) );
>
> The copy constructor also takes a reference.  The only difference between 
> constructing 'w' and calling 'swap' on it is that the former takes a const 
> reference.

You are permitted to bind rvalues to const references, even when it
requires creation of a temporary.  This is 8.5.3 [dcl.init.ref] in the
C++ standard.

-- 
Daniel Jacobowitz
CodeSourcery



Reply to: