Why do struct literals count as lvalues?

Jonathan M Davis jmdavisProg at gmx.com
Thu Aug 18 15:35:13 PDT 2011


On Thursday, August 18, 2011 13:33 Trass3r wrote:
> Am 18.08.2011, 22:19 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:
> > Yeah. I don't understand why a struct literal would be an lvalue. It's a
> > temporary. What possible value does it have? It's not a variable. It
> > doesn't
> > refer to a variable. Why would you be able to assign to anything which
> > is not
> > a variable (or indirectly refers to one - e.g. with ref)?
> 
> I don't understand it either.
> It only makes sense with const ref.

It doesn't even make sense with const ref IMHO - not unless you're going to 
allow const ref to be bound to temporaries in general. I see _zero_ reason to 
treat a newly constructed object as any different from one which is returned 
from a function. It just confuses things. And in a sense, a newly constructed 
object _is_ returned by a function, it's just that it's the constructor rather 
than a normal function.

- Jonathan M Davis


More information about the Digitalmars-d mailing list