-preview=in might break code

Iain Buclaw ibuclaw at gdcproject.org
Mon Oct 5 17:46:20 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.

None of the posted examples I've seen here affect the 
implementation being trialed in GDC.  Though I've already said 
that I'm likely being more conservative than DMD.


More information about the Digitalmars-d mailing list