digitalmars.D.bugs - bug with inner struct templates
- Sean Kelly (40/40) Feb 09 2006 Don's comment about how D templates are resolved during compilation
- Thomas Kuehne (14/54) Feb 12 2006 -----BEGIN PGP SIGNED MESSAGE-----
Don's comment about how D templates are resolved during compilation
instead of optimization got me thinking whether the traditional get/set
accessor method for tuples could be replaced by a simple alias, which
seems ideal as it doesn't rely on inlining to make the resulting code
efficient. What follows is an attempt at this, first with a class, then
with a struct. Note that the class version compiles but the struct
version breaks. I assume this is a bug?
C:\code\d>type test.d
void main()
{
ClassOf!(int) c = new ClassOf!(int)();
StructOf!(int) s;
int x;
c.ref!() = x;
x = c.ref!();
s.ref!() = x;
x = s.ref!();
}
class ClassOf(Type)
{
Type val;
template ref()
{
alias val ref;
}
}
template StructOf( Type )
{
struct StructOf
{
Type val;
template ref()
{
alias val ref;
}
}
}
C:\code\d>dmd test.d
test.d(10): this for val needs to be type StructOf not type StructOf
C:\code\d>
Feb 09 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sean Kelly schrieb am 2006-02-09:
Don's comment about how D templates are resolved during compilation
instead of optimization got me thinking whether the traditional get/set
accessor method for tuples could be replaced by a simple alias, which
seems ideal as it doesn't rely on inlining to make the resulting code
efficient. What follows is an attempt at this, first with a class, then
with a struct. Note that the class version compiles but the struct
version breaks. I assume this is a bug?
C:\code\d>type test.d
void main()
{
ClassOf!(int) c = new ClassOf!(int)();
StructOf!(int) s;
int x;
c.ref!() = x;
x = c.ref!();
s.ref!() = x;
x = s.ref!();
}
class ClassOf(Type)
{
Type val;
template ref()
{
alias val ref;
}
}
template StructOf( Type )
{
struct StructOf
{
Type val;
template ref()
{
alias val ref;
}
}
}
C:\code\d>dmd test.d
test.d(10): this for val needs to be type StructOf not type StructOf
C:\code\d>
Added to DStress as
http://dstress.kuehne.cn/run/a/alias_31_A.d
http://dstress.kuehne.cn/run/a/alias_31_B.d
http://dstress.kuehne.cn/run/a/alias_31_C.d
http://dstress.kuehne.cn/run/a/alias_31_D.d
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFD7vBg3w+/yD4P9tIRAqkhAKCXudGCkdnk3esvKxk2J4/pA7+cNACgjEXU
U3AYB6al6PNUa5WpvVLle6A=
=B7ZY
-----END PGP SIGNATURE-----
Feb 12 2006








Thomas Kuehne <thomas-dloop kuehne.cn>