static assert / static if

Lionello Lunesu lio at
Fri Feb 23 02:18:43 PST 2007

I'm confused:

template factorial(int n)
	static assert(n>0);
	static if (n == 1)
		const factorial = 1;
		const factorial =
			n * factorial!(n-1);

int main()
	return factorial!(0);

The static assert doesn't trip. If I remove the recursion, it works 
fine, but with it the compiler stops with:

ct.d(8): template instance ct.factorial!(-3078) recursive expansion

At first I thought that the template is instantiated before the assert 
is tested, but the static if IS tested before recursion, so why isn't 
the assert? Is it a bug?


More information about the Digitalmars-d-learn mailing list