DIP 1016--ref T accepts r-values--Formal Assessment

Manu turkeyman at gmail.com
Wed Jan 30 17:15:36 UTC 2019


On Tue., 29 Jan. 2019, 10:25 pm Walter Bright via Digitalmars-d-announce <
digitalmars-d-announce at puremagic.com wrote:

> On 1/29/2019 3:45 AM, Andrei Alexandrescu wrote:
> > I am talking about this:
> >
> > int[] a = cast(int[]) alloc.allocate(100 * int.sizeof);
> > if (alloc.reallocate(a, 200 * int.sizeof)
> > {
> >      assert(a.length == 200);
> > }
>
> Even simpler:
>
>    void func(ref void* p) {
>      free(p);                     // frees (1)
>      p = malloc(100);              // (2)
>    }
>
>    int* p = cast(int*)malloc(16);  // (1)
>    func(p);                        // p copied to temp for conversion to
> void*
>    free(p);                        // frees (1) again
>                                    // (2) is left dangling
>
> It's a memory corruption issue, with no way to detect it.
>

Why are you so stuck on this case? The DIP is about accepting rvalues, not
lvalues...
Calling with 'p', an lvalue, is not subject to this DIP.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20190130/1f98e75d/attachment.html>


More information about the Digitalmars-d-announce mailing list