structs are now lvalues - what is with "auto ref"?

jerro a at a.com
Sun Dec 30 06:12:01 PST 2012


On Sunday, 30 December 2012 at 13:57:26 UTC, Namespace wrote:
>> I've played with this a bit today. The code is at 
>> https://github.com/jerro/dmd/tree/auto-ref. I know next to 
>> nothing about DMD, so it could be all kinds of wrong, but it 
>> does at least seem to work.
>>
>> What do you think should happen in this case:
>>
>> void foo(auto ref int a){}
>> void foo(int a){}
>> ...
>> foo(1);
>>
>> should this be an error, or should the second overload be 
>> called?
>
> IMO the second overload (foo(int a)) should be called and the 
> compiler shouldn't do anymore, because all necessary functions 
> exists.
>
>> And what about this:
>>
>> void foo(auto ref int a){}
>> void foo(ref int a){}

> IMO the auto ref function should be replaced by void foo(int 
> a){ }. Then all necessary functions exists also.

These aren't template functions. They must both be generated, 
whether they are used or not. And if they are both generated, 
name mangling for auto ref must be different, or the linker will 
complain.

>
> Nice work so far, but I don't see any tests for it.
> I hope it will be merged in this release.

Don't get your hopes up. This could have all kinds of problems, 
for example, it doesn't work for const auto ref yet. And even if 
it worked perfectly it's probably to late to merge it in this 
release.


More information about the Digitalmars-d-learn mailing list