Naturally, this won't compile:
int &z = 3; // error: invalid initialization of non-const reference ....
and this will compile:
const int &z = 3; // OK
Now, consider:
const int y = 3;
int && yrr = y; // const error (as you would expect)
int && yrr = move(y); // const error (as you would expect)
But these next lines do compile for me. I think it shouldn't.
int && w = 3;
int && yrr = move(3);
void bar(int && x) {x = 10;}
bar(3);
Wouldn't those last two lines allow the literal 3 to be modified? What is the difference between 3
and a const int? And finally, Is there any danger with 'modifying' literals?
(g++-4.6 (GCC) 4.6.2 with -std=gnu++0x -Wall -Wextra
)