On Tue., 29 Jan. 2019, 10:25 pm Walter Bright via Digitalmars-d-announce <
digitalmars-d-announce@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.

>
              • ... Olivier FAURE via Digitalmars-d-announce
              • ... Paul Backus via Digitalmars-d-announce
              • ... 12345swordy via Digitalmars-d-announce
              • ... Andrei Alexandrescu via Digitalmars-d-announce
              • ... Olivier FAURE via Digitalmars-d-announce
              • ... Nicholas Wilson via Digitalmars-d-announce
              • ... Manu via Digitalmars-d-announce
              • ... Steven Schveighoffer via Digitalmars-d-announce
              • ... Manu via Digitalmars-d-announce
              • ... Andrei Alexandrescu via Digitalmars-d-announce
          • Re: D... Manu via Digitalmars-d-announce
    • Re: DIP 1016--ref... Olivier FAURE via Digitalmars-d-announce
  • Re: DIP 1016--ref T ac... Don via Digitalmars-d-announce
  • Re: DIP 1016--ref T ac... bitwise via Digitalmars-d-announce

Reply via email to