std.container.array of struct inside a struct fails

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 14 09:42:59 PDT 2017


14.07.2017 19:12, Anton Fediushin пишет:
> This code:
> -----
> import std.container.array;
>
> struct Test {
>     Array!Test t;
> }
> -----
>
> Fails with an error:
> -----
> /usr/include/dlang/dmd/std/traits.d(2404): Error: struct arrayissue.Test
> no size because of forward reference
>
It's because Array(T) is a value type and needs type size to define 
itself, so you have expected forward reference. But T[] is reference 
type and its size is known in advance - it doesn't depend on type, it's 
always pointer.sizeof + length.sizeof, for 64x architecture it is 16 
bytes, so in this case you have no the issue.
It's not a bug at all.


More information about the Digitalmars-d-learn mailing list