-preview=in might break code

Mathias LANG geod24 at gmail.com
Tue Oct 6 07:38:43 UTC 2020


On Monday, 5 October 2020 at 17:18:57 UTC, Walter Bright wrote:
> On 10/5/2020 4:32 AM, Iain Buclaw wrote:
>> I don't consider there to be any difference between the two as 
>> far as parameter passing is concerned.  As I understood from 
>> the review, the point of ref passing is to elide copies.
>
> I see a major difference, as relying on the number of copies is 
> not the same as memory corruption. Eliding copies is the bread 
> and butter of optimizers, btw.
>
> > Because this is allowed as an optimization only, none of
> > what it does should spill out into user code.  If people
> notice then something
> > has gone wrong in the implementation.
>
> The examples posted here shows it DOES.
>
> If an `in` passes by `const ref`, and another mutable reference 
> to the same memory object decides to free the memory, the `in` 
> reference now is a live dangling pointer.

The complains seem to be about observable difference, not memory 
corruption.
It was suggested a few times that `in` should just be `ref`. If 
the current status is really unworkable (but again, I recommend 
anyone to give it a try first), that would be my preferred course 
of action. The issue of freeing live data is not specific to 
`in`, it shows up with `ref` and pointers as well.


More information about the Digitalmars-d mailing list