Singletons, alias this and DMD crashing

Leandro Motta Barros lmb at stackedboxes.org
Wed May 8 14:20:31 PDT 2013


Hello,

I was toying with the idea of adding an 'alias instance this' to a
low-lock singleton, to allow calling MySingleton.method(), instead of
MySingleton.instance.method().

When I tried this, however, DMD 2.062 crashed. Under Linux, after
chewing the code for a long time, it exits with "Error: out of
memory". Under Windows (or rather, dmd.exe under Wine, which is what I
actually tried), it crashes with a "Stack overflow" error.

I reduced offending code to this:

class S
{
   static @property S instance()
   {
      if (_i is null) // #1
         _i = new S();

      return _i;
   }

   static S _i;

   alias instance this;  // #2
}

Commenting out either of the lines marked with "#n" avoids the crash
(but ruins my code, naturally :-P).

Is this a known bug? I didn't found it in the bug tracker, but I
couldn't really think of good keywords to look for.

Cheers,

LMB


More information about the Digitalmars-d mailing list