www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug? A template mixin inside class makes the dtor of class being invoked 3 times

reply thesys <shaoyoushi gmail.com> writes:
hi,
I got sth wrong with D 1.033. Is there a bug?

It's the source code compiled with dmd 1.033
-------------------------------------------------------------------------
extern (C) int printf(char *, ...);

class Bar
{
	this()
	{
		printf("Bar.this()\n");
	}
	~this()
	{
		printf("Bar.~this()\n");
	}
	mixin Foo;
};

template Foo()
{
}

int main(char[][] args)
{
	scope Bar bar = new Bar();
	return 0;
}
--------------------------------------------------------------------

But the output is:
--------------------------------------------------------------------
Bar.this()
Bar.~this()
Bar.~this()
Bar.~this()
-------------------------------------------------------------------
The dtor of class Bar was invoked 3 times. Why?
Jul 19 2008
parent "Koroskin Denis" <2korden+dmd gmail.com> writes:
On Sat, 19 Jul 2008 18:12:28 +0400, thesys <shaoyoushi gmail.com> wrote:

 hi,
 I got sth wrong with D 1.033. Is there a bug?

 It's the source code compiled with dmd 1.033
 -------------------------------------------------------------------------
 extern (C) int printf(char *, ...);

 class Bar
 {
 	this()
 	{
 		printf("Bar.this()\n");
 	}
 	~this()
 	{
 		printf("Bar.~this()\n");
 	}
 	mixin Foo;
 };

 template Foo()
 {
 }

 int main(char[][] args)
 {
 	scope Bar bar = new Bar();
 	return 0;
 }
 --------------------------------------------------------------------

 But the output is:
 --------------------------------------------------------------------
 Bar.this()
 Bar.~this()
 Bar.~this()
 Bar.~this()
 -------------------------------------------------------------------
 The dtor of class Bar was invoked 3 times. Why?
I confirm. Same output for 1.029, 1.031 and 2.017 BTW, scope may be omitted, same result.
Jul 19 2008