Bug 7751 – [ICE] (Regression 2.059head) From auto and forward reference
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-22T05:17:00Z
Last change time
2012-03-29T15:20:15Z
Keywords
ice, pull
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-03-22T05:17:25Z
This is wrong D2 code because Foo has no constructor:
class Foo(T) {
T x;
Foo y;
}
auto foo(T)(T x, Foo!T y=null) {
return new Foo!T(x, y);
}
void bar(U)(U foo, U[] spam=[]) {
spam ~= [];
}
void main() {
bar(foo(0));
}
DMD 2.059head gives:
test.d(6): Error: no constructor for Foo
test.d(12): Error: template instance test.foo!(int) error instantiating
Followed by a crash.
If I remove the template of Foo:
class Foo {
int x;
Foo y;
}
auto foo(int x, Foo y=null) {
return new Foo(x, y);
}
void bar(U)(U foo, U[] spam=[]) {
spam ~= [];
}
void main() {
bar(foo(0));
}
DMD gives this and no crash:
test.d(6): Error: no constructor for Foo
test.d(12): Error: forward reference to foo
From issue 7778:
> This code snippet crashes DMD 2.059head:
> ---
> auto foo(){bar[]r;r~=[];}
> ---
> It does not crash DMD 2.058
The same reason crashes above code.
Comment #3 by k.hara.pg — 2012-03-25T18:16:58Z
*** Issue 7778 has been marked as a duplicate of this issue. ***
Comment #4 by github-bugzilla — 2012-03-29T12:12:47Z