Why const int
is not an R-value in C++(11)? I thought that R-value was \'anything\' which cannot be on the left hand side and constants fulfil that
The parameter type is an rvalue reference and the standard forbids initialization of an rvalue-reference with an lvalue of a "reference-related" type.
8.5.3 References [dcl.init.ref ]
...
5 ... If T1 is reference-related to T2 and the reference is an rvalue reference, the initializer expression shall not be an lvalue.
Hence, the following is an error:
void f (long &&);
const long x = 1;
void g () { f (x); }
But the following is not:
void f (long &&);
const int x = 1;
void g () { f (x); }
So, the reason for the error is not simply "the initialization is not with an rvalue", but because "the initialization is with an lvalue of a reference-related type."