unittests running before static ctors??

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 26 10:20:28 PST 2012


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.


T

-- 
People tell me that I'm skeptical, but I don't believe it.


More information about the Digitalmars-d-learn mailing list