Taking the address of an rvalue struct

Cristi Cobzarenco cristi.cobzarenco at gmail.com
Fri Jul 22 10:41:08 PDT 2011


I don't think it's neccessary to prolong their life till the end of
the scope, but as it stands their lifetime has to be at least as long
as the expression their in. I think that we should only disallow
non-const method calls, const methods conceptually make sense on
literals. Also disallowing method calls would conceivably also mean
disallowing operator overloads to work and one would not be able to
write stuff like Complex!double(-1.0,1.0) * z - which would be very
inconvenient.


---
Cristi Cobzarenco
BSc in Artificial Intelligence and Computer Science
University of Edinburgh
Profile: http://www.google.com/profiles/cristi.cobzarenco



On 22 July 2011 19:26, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 7/22/11 12:10 PM, dsimcha wrote:
>>
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>> article
>>>
>>> This has long been a feature that I attempted to remove several times.
>>
>> What?  Taking the address of this?  Invoking methods on rvalue structs?
>
> The latter.
>
>>> It steps from the fact that you can invoke methods on rvalue structs.
>>> Disallowing that would solve the issue, but would also eliminate a lot
>>> of convenience.
>>
>> I think invoking methods on rvalue structs needs to be allowed come Hell
>> or high
>> water.  What's wrong with just banning any optimization of rvalue structs
>> that
>> have methods called on them, i.e. requiring the compiler to treat them the
>> same as
>> named methods, allocate stack space for them that doesn't get reused
>> elsewhere in
>> the same function, etc.?
>
> Prolonging the lifetime of temporaries to the end of the enclosing function
> would be interesting, but perhaps surprising. Not to mention inefficient.
>
>
> Andrei
>


More information about the Digitalmars-d mailing list