www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17230] New: Destroy forward reference error


          Issue ID: 17230
           Summary: Destroy forward reference error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: radu.racariu gmail.com

This reduced test:

struct A
     B b;

struct B
    Wrap!A val;
struct Wrap(T)
    T* t;

compiler: dmd 2.073.1

fails with:
Error: struct f909.A no size because of forward reference
/d934/f909.d(14): Error: template instance object.destroy!(A) error
/d934/f909.d(8):        instantiated from here: Wrap!(A)

As per http://forum.dlang.org/thread/uplymqtaxubgkxwzacrz forum.dlang.org and
this http://ddili.org/ders/d.en/memory.html#ix_memory.destroy - it looks that
destroy needs to be called by dereferencing the pointer in order for the T dtor
to be called. The fwd ref error makes it impossible to use destroy.

The workaround is to use delete t to get the dtor called without deref, but it
is hacky!

Feb 27 2017