Jonathan M Davis:
I believe that if a particular template is ever instantiated
more than 50
times recursively, the compiler will error out on the
assumption that it's hit
infinite recursion (it has to bottom out eventually, or would
just end up
running until it ran out of memory if it actually does hit
infinite recursion;
I don't know how arbitrary the choice of 50 was).
I think currently the limit is 500 (time ago it was smaller, but
probably higher than 50):
template Foo(int n) {
enum Foo = Foo!(n + 1);
}
pragma(msg, Foo!0);
void main() {}
It gives:
test2.d(2): Error: template instance test2.Foo!(500) recursive
expansion
The 500 limit is quite arbitrary. I like GCC, that defined a
limit, but with
-ftemplate-depth-n you are allowed to increase it to n.
Bye,
bearophile