Steven Schveighoffer wrote:
On Mon, 12 Oct 2009 05:26:58 -0400, bearophile <[email protected]> wrote:

What's wrong with this code?

struct MemoryPool(T) {
    alias T[100_000 / T.sizeof] Chunk;
    Chunk*[] chunks;
}
struct Foo {
    int x;
    MemoryPool!(Foo) pool;
}
void main() {}

It prints "Error: struct problem.Foo no size yet for forward reference".
T.sizeof must be 8 in all cases.

The compiler does this:

Instantiate MemoryPool!(Foo)
But for that it needs to know Foo.sizeof.
But for that it needs to know MemoryPool!(Foo).sizeof.
But for that it needs to instantiate MemoryPool!(Foo) and find it's size.
etc.

I can see MemoryPool!(Foo) sizeof doesn't depend at all of T.sizeof because it just has a pointer. But how do you suggest to fix the compiler to understand that?

What I can see is that to know MemoryPool!(Foo).sizeof the type of the alias doesn't need to be solved completely... but what would you recommend the compiler to do?

Reply via email to