D-Programming-Language/dmd — pull request #2940 by 9rnsr (2013-12-09 15:46:36+00:00)
Title: Issue 5185 - Recursive template expansion error in class method

https://d.puremagic.com/issues/show_bug.cgi?id=5185

As the test casein 5185, `checkRecursiveExpansion` would prevent legitimate template instantiation.

If a template instance depends on the definition of itself, it is a true "recursion". But, a declaration sometimes can depend on the declaration itself.

For example, a class can have same class reference in its field (`class C { C field; }`). All of class types are references in D, so its type size (== definition) is equal to pointer size. So, even if self class type is used in its declaration, it won't cause definition recursion, because compiler can treat the class definition as opaque during semantic analysis of the declaration.

Returning to the template instance case, compiler cannot treat instance definition as opaque. However, to put it another way, compiler cannot detect the "true recursion" until instantiating the template. In other words, we cannot detect template recursion by merely seeing template arguments.

Therefore, I think the check is merely unnecessary. We have to rely on the nest level detector of template instantiations, and circular chain detector of `tinst` during semantic3.