D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17230 - Destroy forward reference error
Summary: Destroy forward reference error
Status: RESOLVED DUPLICATE of issue 17267
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-27 15:02 UTC by RR
Modified: 2017-11-25 06:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description RR 2017-02-27 15:02:37 UTC
This reduced test:

-------------code-------------
struct A
{
     B b;
}

struct B
{
    Wrap!A val;
}
struct Wrap(T)
{
   ~this()
    {
        destroy(*t);
        destroy(t);
    }
    T* t;
}
-------------code-------------

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 instantiating
/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!
Comment 1 Mike Franklin 2017-11-25 06:41:32 UTC
This doesn't appear to have anything to do with `destroy`.  You can reproduce the same error with the following code

struct A
{
     B b;
}

struct B
{
    Wrap!A val;
}

struct Wrap(T)
{
   ~this()
    {
        assert(T.sizeof == 0);
    }
}

onlineapp.d(15): Error: struct onlineapp.A no size because of forward reference

See https://run.dlang.io/is/TC4uxk

So, the error seems to be due to a bug in DMD's template instantiation.  If the template is instantiated manually with something like this...

struct A
{
     B b;
}

struct B
{
    C val;
}

struct C
{
   ~this()
    {
        assert(A.sizeof == 0);
    }
}

void main() {}

... it works fine.  See https://run.dlang.io/is/iPAFN8
Comment 2 Mike Franklin 2017-11-25 06:50:30 UTC

*** This issue has been marked as a duplicate of issue 17267 ***