-preview=in might break code

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 3 18:36:57 UTC 2020


On 10/3/20 12:56 PM, Mathias LANG wrote:
> On Saturday, 3 October 2020 at 13:05:43 UTC, Andrei Alexandrescu wrote:
>>
>> [...]
>>
>> * This has been discussed in C++ circles a number of times, and 
>> aliasing has always been a concern. If /C++/ deemed that too 
>> dangerous... <insert broadside>. A much more explicit solution has 
>> been implemented in 
>> https://www.boost.org/doc/libs/1_66_0/libs/utility/call_traits.htm.
> 
> I don't deny that aliasing can create issues that could be very hard to 
> debug.

Cool. I hope we now agree there's evidence that such situations are not 
just hypothetical.

> But the problem of aliasing is not limited to `in`: code that uses 
> `const ref` (or a  `const T` where `T` has indirection) can already 
> misbehave if it doesn't take into account the possibility of parameter 
> aliasing.
> 
> To put it differently: Why is `auto ref` acceptable but `in` is not ?

A good point. I can tell for myself. First, binding to reference vs. 
value is always reproducible the same regardless of platform 
particulars. Granted, maintenance is liable to introduce puzzlers but 
more of a first-order nature (change a call, get different resuts) as 
opposed to a long-distance issue (add a field to the object, suddenly 
unrelated code breaks - not to mention changes in compiler heuristics). 
Second, the keyword "ref" is in there, which is a clear giveaway the 
implementation code needs to expect that.


More information about the Digitalmars-d mailing list