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.)