www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2146] New: Multiple execution of 'static this' defined in template

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2146

           Summary: Multiple execution of 'static this' defined in template
           Product: D
           Version: 1.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: samukha voliacable.com


File a:
----
module a;

import b;

alias Foo!(int) foo;

void main()
{
}
----


File b:
----
module b;
import std.stdio;

template Foo(T)
{
   T x;     
   static this()
   {
      writefln("Initing " ~ T.stringof);
      T x = T.init; // less trivial initialization here.
   }
}

void baz()
{
    alias Foo!(int) bar;
}
----

Output:
Initing int
Initing int


Note that the constructor is executed only once if we move 'alias Foo!(int)
bar;' out of baz() to the scope of module b.


-- 
Jun 09 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2146





------- Comment #1 from samukha voliacable.com  2008-06-09 08:22 -------
'T x = T.init;' in the template should read 'x = T.init;', sorry:

File a:
----
module a;

import b;

alias Foo!(int) foo;

void main()
{
}
----


File b:
----
module b;
import std.stdio;

template Foo(T)
{
   T x;     
   static this()
   {
      writefln("Initing " ~ T.stringof);
      x = T.init; // less trivial initialization here.
   }
}

void baz()
{
    alias Foo!(int) bar;
}
----


-- 
Jun 09 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2146


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla digitalmars.com  2008-06-22 19:00 -------
Fixed dmd 1.031 and 2.015


-- 
Jun 22 2008