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?
int&
. – Tremannfoo
should not compile for reasons given in the question – Claverreturn (r);
, it would work by design). – Nebulize