www.digitalmars.com         C & C++   DMDScript  

D - [Bug?] struct inside template

template T(T)
{
struct Foo
{
static Foo test(Foo f)
{
Foo a = f;
return f;
}
}
}

alias T!(char).Foo Foo; // line 14 here!
alias T!(float).Foo Foo_b;

int main(char[][] arg)
{
Foo_b a;
Foo_b b;
b.test(a);
Foo_b.test(a);

return 0;
}

/*
Using Digital Mars D Compiler v0.79.

When I comment out line 14  ( alias T!(char).Foo Foo; )
The error message below appears.

struct_test.d(8): identifier 'Foo' is not defined

When I uncomment line 14.
Cast error shows up.

sym.parent: T!(char), deco = S11struct_test11__anonymous3T_a3Foo
sym.parent: T!(float), deco = S11struct_test11__anonymous3T_f3Foo
struct_test.d(8): cannot implicitly convert Foo to Foo

There may be a kind of problem with name resolution of struct inside template?
Typeof function argument "Foo" and typeof "Foo" in function body may be
mismatch.

If this is a fault or a imcompleted feature.
I hope the D compiler to be tempered more.

Use of alias could be a workaround. ( not carefully tested. forgive me.. )

template T(T)
{
struct Foo
{
alias Foo FooS;
static Foo test(FooS f)
{
FooS a = f;
return f;
}
}
}

*/
Feb 10 2004