[Issue 11292] New: Cannot re-initialize a const field in postblit

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 18 05:54:30 PDT 2013


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

           Summary: Cannot re-initialize a const field in postblit
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: samukha at voliacable.com


--- Comment #0 from Max Samukha <samukha at voliacable.com> 2013-10-18 05:54:29 PDT ---
struct S
{
    immutable int x;

    this(int x)
    {
        this.x = x;
    }

    this(this) {
        x = 1;
    }
}

void main() {
    S s = S(1);
    S s2 = s;
}

Error: can only initialize const member x inside constructor

Postblit is a constructor. Why re-initialization is allowed for the state
copied from .init and not for the state copied from the source struct?

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