Why does this rvalue reference bind to an lvalue?

Viewed 432

I do not understand why the following code compiles on GCC 8.0:

decltype(auto) foo(int&& r) {
    return r;
}

In foo, the declaration type of r is int&&, and so the return type of foo is also int&&. But r itself is an lvalue, and an lvalue cannot bind to an rvalue reference.

Am I missing something?

1 Answers
Related