context-free grammar

Mafi mafi at example.org
Sat Mar 5 05:39:32 PST 2011


Am 05.03.2011 13:10, schrieb Peter Alexander:
> On 5/03/11 4:39 AM, Jonathan M Davis wrote:
>> On Friday 04 March 2011 20:31:38 Walter Bright wrote:
>>> uri wrote:
>>>> Explain why (a*b) is lvalue in bearophile's second example.
>>>
>>> Because the expression evaluates to a temporary, which is an lvalue.
>>>
>>>> This is one of the weird things in D. The language is too complex. It
>>>> takes years to find out about the corner cases.
>>>
>>> It's not a weird corner case at all. Temporaries can be used as
>>> lvalues (in
>>> C++ too).
>>
>> Really? I thought that a temporary was pretty much _the_ classic
>> example of an
>> rvalue. If you can assign to temporaries, you can assign to most
>> anything then,
>> other than literals. Why on earth would assigning to temporaries be
>> permitted?
>> That just seems unnecessary and bug-prone.
>>
>> - Jonathan M Davis
>
> How do you think array assignments in C++ work?
>
> a[i] = x;
>
> a[i] is just *(a + i), i.e. the evaluation of an expression that yields
> a temporary, which in this case is an lvalue. Same applies to all other
> operator[] overloads.

No, the temporary in this case is not an lvalue. It's an adress whose 
value is an lvalue.
The results of operator[] is a reference not a normal value. A reference 
is an adress which is always implicitly derefenced when used.
In D we use opIndexAssign anyways.

Mafi


More information about the Digitalmars-d mailing list