-preview=in might break code
Walter Bright
newshound2 at digitalmars.com
Mon Oct 5 17:18:57 UTC 2020
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.
More information about the Digitalmars-d
mailing list