non-const reference to temporary (was: non-const copy ctor)

Christian Fröbel
Sun Apr 9 20:14:00 GMT 2006

Hi Andrew,

Andrew Haley wrote:
> [...]
> I can.  "The initializer of a const T& need not be an lvalue..."  In
> other words, although he doesn't explicitly say so, the initializer of
> a const T& has to be an lvalue.

Yes, I guessed so as well. But what's the reason for this decision?

>  > I understand that it generally doesn't make sense to alter a
>  > temporary object. But why forbid it?
> Because, semantically speaking, it makes no sense.

Yes, mostly. And that this is forbidden imposes a problem in the rare cases 
where it does make sense. And in those cases where someone does not want to 
use const at all (like me).


> But we're way off topic now.
> Andrew.

More information about the Gcc-help mailing list