Call site 'ref'

Timon Gehr timon.gehr at gmx.ch
Sun Jan 15 14:44:54 PST 2012


On 01/15/2012 11:36 PM, Timon Gehr wrote:
> On 01/15/2012 11:41 PM, Peter Alexander wrote:
>> On 15/01/12 10:10 PM, Timon Gehr wrote:
>>> Another thing that would have to be discussed: what happens to const ref
>>> parameters? It is very reasonable that someone will decide to change
>>> calling conventions from by value to by const ref or the other way round
>>> after profiling. It is very convenient that such a change is
>>> syntactically transparent to the caller and this should stay.
>>
>> Actually, that would be very dangerous. const ref does not have the
>> privilege of being able to bind to rvalues in D like it does in C++.
>>
>> void foo(const ref int x) {...}
>>
>> foo(1); // this is legal in C++, but illegal in D
>>
>
> Who on earth wants to change an int parameter from by value to by const
> ref? struct literals can bind to const ref parameters so there is
> absolutely no issue.
>
>> In case, const ref would not require the ref at call site because
>> there's no danger of it being modified.
>>
>
> The semantics are still not the same.

(Even the claim that there is no danger of it being modified is plain wrong)


More information about the Digitalmars-d mailing list