2

In studying rvalues and rvalue references, I've been pointed to the excellent posting https://stackoverflow.com/a/11540204/368896, in which appears the following table:

            lvalue   const lvalue   rvalue   const rvalue
---------------------------------------------------------              
X&          yes
const X&    yes      yes            yes      yes
X&&                                 yes
const X&&                           yes      yes

Note that the table indicates that an rvalue cannot bind to a non-const lvalue reference.

However, in VS2010 I seem to be able to do so:

class A
{};

int main()
{
    A & a = A(); // Binding an rvalue to a non-const lvalue reference?
}

Where is my misunderstanding?

Community
  • 1
  • 1
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181

1 Answers1

3

This is a compiler "extension" (or "bug", depending on your perspective) of the Microsoft compiler. C++ only allows non-const binding of an lvalue to a non-const lvalue reference.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084