unittests running before static ctors??

Jonathan M Davis jmdavisProg at gmx.com
Thu Jan 26 10:22:55 PST 2012


On Thursday, January 26, 2012 10:20:28 H. S. Teoh wrote:
> On Thu, Jan 26, 2012 at 01:10:28PM -0500, Jonathan M Davis wrote:
> > On Thursday, January 26, 2012 10:08:24 H. S. Teoh wrote:
> > > I just noticed that unittests are running before static class ctors.
> > > Is
> > > this a bug??
> 
> [...]
> 
> > I would definitely think that that's a bug. If you're seeing that
> > happen,
> > please report it.
> 
> [...]
> 
> Hmm. It appears that I'm misunderstanding D syntax. What does a "static
> {...}" block in a class mean? I had this code:
> 
> class A {
> static {
> this() { ... }
> ...
> }
> unittest { ... }
> }
> 
> It appears that this() is being interpreted as a non-static ctor, which
> is why it is never run before the unittest (it's never run at all). When
> I change it to:
> 
> class A {
> static this() { ... }
> static { ... }
> unittest { ... }
> }
> 
> Then it works as expected. So I guess I don't quite understand what a
> static {...} block means.

static {} should make all of the declarations within it static. If you did 
public {} it would make all of the declarations in it public, or if you did 
pure {} it would make all of the declarations in it pure. It looks like you 
ran into this bug:

http://d.puremagic.com/issues/show_bug.cgi?id=5868

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list