www.digitalmars.com         C & C++   DMDScript  

D - [Bug?] struct inside template

reply berupon <berupon_member pathlink.com> writes:
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;
}
}
}

*/


hogehogemogemoge
Feb 10 2004
parent reply Tintor Marko <elud verat.net> writes:
typedef char[] string;
int main(string[] args)
{
	return 0;
}

DMD 0.79 linux: function main parameters must be main() or main(char[][] 
args)

string[] is char[][]
Feb 10 2004
parent Roel Mathys <roel.mathys yucom.be> writes:
Tintor Marko wrote:
 typedef char[] string;
 int main(string[] args)
 {
     return 0;
 }
 
 DMD 0.79 linux: function main parameters must be main() or main(char[][] 
 args)
 
 string[] is char[][]
try this: alias char[] string; int main(string[] args) { return 0; } it will do, because "typedef" defines a new type, "alias" one can create an alias :-), and no new type is defined bye, roel
Feb 10 2004