www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - template bugs

reply tetsuya <tetsuya_member pathlink.com> writes:
win XP, dmd0109

I found some bugs in template.



1. unexpected compilation

dot-missing template expression is compiled (ignored?)
without causing any error.

<code>
import std.stdio;

template T()
{
class T
{
static void foo() { writefln("Hello World"); }	// not executed, though
}
}

void main()
{
T!()foo;		// missing *DOT* !!
}
</code>



2. lookup symbol error

It gives a funny message
# test.d(4): cannot implicitly convert expression this of type A to A


<code>
template T()
{
A a;
class A { this() { T!().a = this; } }	// line 4
}

void main()
{
mixin T!();
}
</code>

It works if you change mixin to alias.



3. Fatal error: out of memory

It causes a fatal error: out of memory, after dmd said
# test.d(4): constructor test.main.T!().A.this cannot access frame of function
main
Maybe the same bug with the previous one?

<code>
template T()
{
A a;
class A { this() { a = this; } }	// line 4
}

void main()
{
mixin T!();
}
</code>



cheers!

-tetsuya
Dec 13 2004
next sibling parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Added to DStress as
http://svn.kuehne.cn/dstress/run/template_07.d
http://svn.kuehne.cn/dstress/run/template_08.d
http://svn.kuehne.cn/dstress/nocompile/template_09.d

Thomas

tetsuya schrieb am Mon, 13 Dec 2004 13:20:58 +0000 (UTC):
 win XP, dmd0109

 I found some bugs in template.



 1. unexpected compilation

 dot-missing template expression is compiled (ignored?)
 without causing any error.

<code>
 import std.stdio;

 template T()
 {
 class T
 {
 static void foo() { writefln("Hello World"); }	// not executed, though
 }
 }

 void main()
 {
 T!()foo;		// missing *DOT* !!
 }
</code>



 2. lookup symbol error

 It gives a funny message
 # test.d(4): cannot implicitly convert expression this of type A to A


<code>
 template T()
 {
 A a;
 class A { this() { T!().a = this; } }	// line 4
 }

 void main()
 {
 mixin T!();
 }
</code>

 It works if you change mixin to alias.



 3. Fatal error: out of memory

 It causes a fatal error: out of memory, after dmd said
 # test.d(4): constructor test.main.T!().A.this cannot access frame of function
 main
 Maybe the same bug with the previous one?

<code>
 template T()
 {
 A a;
 class A { this() { a = this; } }	// line 4
 }

 void main()
 {
 mixin T!();
 }
</code>



 cheers!

 -tetsuya

-----BEGIN PGP SIGNATURE----- iD8DBQFBwHdZ3w+/yD4P9tIRAjWWAJ9lwjYtwg9iCAh3S4qLHv2y47GWDACePQVR ag2GYH13PsjbOQYWI2EqyU4= =Hph4 -----END PGP SIGNATURE-----
Dec 15 2004
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"tetsuya" <tetsuya_member pathlink.com> wrote in message
news:cpk4vq$1m5a$1 digitaldaemon.com...
 1. unexpected compilation

 dot-missing template expression is compiled (ignored?)
 without causing any error.

 <code>
 import std.stdio;

 template T()
 {
 class T
 {
 static void foo() { writefln("Hello World"); } // not executed, though
 }
 }

 void main()
 {
 T!()foo; // missing *DOT* !!
 }
 </code>

Actually, this declares 'foo' to be an instance of template T!(). It's a feature, not a bug.
 2. lookup symbol error

 It gives a funny message
 # test.d(4): cannot implicitly convert expression this of type A to A


 <code>
 template T()
 {
 A a;
 class A { this() { T!().a = this; } } // line 4
 }

 void main()
 {
 mixin T!();
 }
 </code>

 It works if you change mixin to alias.

Although the error message is confusing, what's happening is that the T!().a is not referring to the mixin T!(), it is creating a new global instance of T. Hence, the mixin A is different from the instance A.
 3. Fatal error: out of memory

 It causes a fatal error: out of memory, after dmd said
 # test.d(4): constructor test.main.T!().A.this cannot access frame of

 main
 Maybe the same bug with the previous one?

I've got this fixed now. Thanks.
Mar 17 2005