Bug 5185 – (D1 only) Recursive template expansion error in class method

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-11-07T12:22:29Z
Last change time
2019-11-07T08:00:01Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
George

Comments

Comment #0 by indigon — 2010-11-07T12:22:29Z
It's very comfortable to place unittest code near functions. But in template classes in some cases it cannot be done: class C(V) { V v; void foo() { } unittest { C!(C!(int)) c; // Error: recursive template expansion for template argument C!(int).C } } unittest { C!(C!(int)) c; // the same code here don't cause this error }
Comment #1 by andrej.mitrovich — 2013-02-15T14:45:44Z
Unrelated to unittests, and affects D2 too. Reduced: class C(V) { void f() { C!(C!(int)) c; // NG } } void main() { C!(C!(int)) c; // ok }
Comment #2 by k.hara.pg — 2013-12-09T07:47:10Z
Comment #3 by github-bugzilla — 2013-12-10T00:11:31Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a29d09aee89885f59d413b1451e1ec843e1e4985 fix Issue 5185 - Recursive template expansion error in class method 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. https://github.com/D-Programming-Language/dmd/commit/e542c5a746fbe72a984444aab2105ac5dd660ace Merge pull request #2940 from 9rnsr/fix5185 Issue 5185 - Recursive template expansion error in class method
Comment #4 by razvan.nitu1305 — 2019-11-07T08:00:01Z
Does not manifest in D2 and D1 is no longer supported. Closing as WONTFIX