[Issue 2146] New: Multiple execution of 'static this' defined in template
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jun 9 06:07:53 PDT 2008
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 at digitalmars.com
ReportedBy: samukha at 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.
--
More information about the Digitalmars-d-bugs
mailing list