www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - static constructor bug

reply Lukas Pinkowski <Lukas.Pinkowski web.de> writes:
There is a problem with static constructors: It seems as prepending this()
directly with static will run the constructor correctly; with an enclosing
static{ this() } the constructor will not be run:


import std.stdio;

class C1
{
  static
  {
    this()
    {
      writefln("C1 static ctor");
    }
  }
}

class C2
{
  static this()
  {
    writefln("C2 static ctor");
  }
}

int main()
{
  return 0;
}


Executing this prog will give me only "C2 static ctor", but not both, as it
should! I'm using Linux DMD version 0.114;

greetings,

Lukas Pinkowski
Mar 07 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lukas Pinkowski schrieb am Tue, 08 Mar 2005 01:52:02 +0100:
 There is a problem with static constructors: It seems as prepending this()
 directly with static will run the constructor correctly; with an enclosing
 static{ this() } the constructor will not be run:


 import std.stdio;

 class C1
 {
   static
   {
     this()
     {
       writefln("C1 static ctor");
     }
   }
 }

 class C2
 {
   static this()
   {
     writefln("C2 static ctor");
   }
 }

 int main()
 {
   return 0;
 }


 Executing this prog will give me only "C2 static ctor", but not both, as it
 should! I'm using Linux DMD version 0.114;
I thought the "static{ this... }" behavior was documented somewhere. Added to DStress as http://dstress.kuehne.cn/run/static_30.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOGKp3w+/yD4P9tIRAppWAJ984EbYbTNkK+dn19KJmUMOBwcwkACfaNH9 lUqXxqJclSRxxlO3MePvz2U= =HAiY -----END PGP SIGNATURE-----
Mar 16 2005