Something wrong with reflection inside struct destructor

Jack Applegame via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 14 07:33:39 PDT 2017


This is completely unacceptable:

DPaste(https://dpaste.dzfl.pl/f54f578c4ec9)

import std.stdio;
import std.string;
import std.experimental.allocator;
import std.experimental.allocator.mallocator : Mallocator;

struct Bar(E) {
     E* ptr = null;
     void allocate(int m) { ptr = Mallocator.instance.make!Foo(m); 
}
     ~this() {
         if(ptr !is null) Mallocator.instance.dispose(ptr);
     }
}

struct A {
     int m;
     ~this() { writefln("A.~this(%s)", m); }
}

struct Foo {
     A a;
     Bar!Foo bar;
     this(int m) { a = A(m); }
}

void main() {
     auto foo = Foo(1);
     foo.bar.allocate(10);
}

Output:
A.~this(1)

Expected output:
A.~this(10)
A.~this(1)

Can someone to fix this ASAP for $100?


More information about the Digitalmars-d mailing list