[Issue 7751] New: [ICE] From auto and forward reference
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Thu Mar 22 05:17:05 PDT 2012
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=7751
           Summary: [ICE] From auto and forward reference
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-03-22 05:17:25 PDT ---
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
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list