Bug 9050 – Too early instantiation of template structs

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-20T08:41:00Z
Last change time
2013-11-26T01:32:53Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
Marco.Leise

Comments

Comment #0 by Marco.Leise — 2012-11-20T08:41:10Z
This is probably some variation of some other bug, but it is hard to tell for me. In the example below there is a recursive instantiation of foo, A and B. It takes both calls to foo and the pure attribute to make the compiler crash. Otherwise it prints: test.d(4): Error: forward reference to inferred return type of function call foo(A()) test.d(8): Error: template instance test.B!(int) error instantiating test.d(10): instantiated from here: foo!() struct A(T) {} struct B(T) { unittest { foo(A!int()); } } auto foo()(A!int base) pure { return B!int(); } auto l = foo(A!int());
Comment #1 by andrej.mitrovich — 2013-02-04T12:38:06Z
Test-case without requiring -unittest: struct A(T) {} struct B(T) { void f() { foo(A!int()); } } auto foo()(A!int base) pure { return B!int(); } auto l = foo(A!int()); void main() { } The crash is gone in 2.061 so this is no longer an ICE. Is the return type inference error expected? Otherwise close with WORKSFORME if this was only an ICE report.
Comment #2 by Marco.Leise — 2013-02-05T08:55:25Z
Ok, I don't quite remember what my thoughts were about the return type inference, but it looks valid for the compiler to reject the code. So I followed your advice and set it to resolved.
Comment #3 by timon.gehr — 2013-02-05T09:06:45Z
(In reply to comment #2) > Ok, I don't quite remember what my thoughts were about the return type > inference, but it looks valid for the compiler to reject the code. So I > followed your advice and set it to resolved. No, that is a bug. There is no reason for the compiler to reject the code. (It even works if B is not templated.)
Comment #4 by k.hara.pg — 2013-11-21T22:17:44Z
Comment #5 by k.hara.pg — 2013-11-21T22:19:34Z
*** Issue 10936 has been marked as a duplicate of this issue. ***
Comment #6 by github-bugzilla — 2013-11-26T01:32:40Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f217367578bdfdda8ed2ab20c18f16005775cc52 fix Issue 9050 - Too early instantiation of template structs https://github.com/D-Programming-Language/dmd/commit/5fb19ce665729e4ee56777c7c61a16fe24684712 Merge pull request #2851 from 9rnsr/fix9050 Issue 9050 - Too early instantiation of template structs