December 30, 2007
The following template bug is hindering several projects of mine. It is likely a variant of issue 945, but it is subtly different and might be a separate issue. We have two files:

---------- tst.d -----------
module tst;
import tst2;

struct Nest(A)
{
    S member;
}

struct T(A)
{
    alias Nest!(A) Nested;
}

alias T!(int) instance;

---------- tst2.d -------------

module tst2;
import tst;

struct S {}

-------------------------

$ dmd -c tst2.d
tst.d(6): struct tst.Nest!(int).Nest has forward references
tst.d(17): template instance tst.T!(int) error instantiating

$ dmd -c tst.d
[works, no error]

Workaround 1: specify all files on one line

dmd tst.d tst2.d

This however is not always practical, it does not work with DSSS/Rebuild and it does not work with gdc.

Workaround 2: instantiate Nest manually

Adding a line to tst.d so the two last lines read:
alias Nest!(int) _unused1;
alias T!(int) instance;

seems to solve the problem, but this seems like a very redundant thing to do.

-N