http://d.puremagic.com/issues/show_bug.cgi?id=6578

           Summary: Ignored const with struct with constructor
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-08-30 04:57:48 PDT ---
In DMD 2.055head this compiles and runs with no errors:


struct Foo {
    int x;
    this(int x_) { this.x = x_; }
}
void main() {
    auto f1 = new const(Foo)(1);
    f1.x++;
    auto f2 = new immutable(Foo)(1);
    f2.x++;
    auto f3 = const(Foo)(1);
    f3.x++;
    auto f4 = immutable(Foo)(1);
    f4.x++;
}


While this generates two errors:

struct Foo {
    int x;
}
void main() {
    auto f5 = const(Foo)(1);
    f5.x++; // error
    auto f6 = immutable(Foo)(1);
    f6.x++; // error
}


I think in the first program the f1,f2,f3,f4 structs too need to raise a
compile-time error.

Thanks to Timon Gehr for a suggestion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to