[Issue 17230] New: Destroy forward reference error
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Feb 27 07:02:37 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17230
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 at puremagic.com
Reporter: radu.racariu at gmail.com
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!
--
More information about the Digitalmars-d-bugs
mailing list