On 15/01/12 10: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.

Are you sure about struct literals binding to const ref? I can't find anything in the language spec or TDPL that supports that claim.

In fact, TDPL says:

"If a function expects a ref, it accepts only "real" data, not temporaries; anything that's not an lvalue is rejected during compilation"

Unfortunately it doesn't say anything explicitly about struct literals or const ref, but that would lead me to believe that they fall under the same rule.

DMD allows struct literals to bind to const ref, but then again it also allows them to bind to ref, so I'm not sure how reliable that is.

This should probably be clarified. It's kind of important.

Reply via email to