Bug 17230 – Destroy forward reference error

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-02-27T15:02:37Z
Last change time
2017-11-25T06:50:30Z
Assigned to
No Owner
Creator
Radu Racariu

Comments

Comment #0 by radu.racariu — 2017-02-27T15:02:37Z
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/[email protected] 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 by slavo5150 — 2017-11-25T06:41:32Z
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 by slavo5150 — 2017-11-25T06:50:30Z
*** This issue has been marked as a duplicate of issue 17267 ***