Bug? A template mixin inside class makes the dtor of class being invoked 3 times

Koroskin Denis 2korden+dmd at gmail.com
Sat Jul 19 07:27:50 PDT 2008


On Sat, 19 Jul 2008 18:12:28 +0400, thesys <shaoyoushi at 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.



More information about the Digitalmars-d mailing list