July 19, 2008 Bug? A template mixin inside class makes the dtor of class being invoked 3 times | ||||
|---|---|---|---|---|
| ||||
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? | ||||
July 19, 2008 Re: Bug? A template mixin inside class makes the dtor of class being invoked 3 times | ||||
|---|---|---|---|---|
| ||||
Posted in reply to thesys | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply