Thread overview
[Issue 10376] New: Glaring hole in const system
Jun 16, 2013
timon.gehr@gmx.ch
Jun 16, 2013
timon.gehr@gmx.ch
Jun 16, 2013
Peter Alexander
Jun 16, 2013
timon.gehr@gmx.ch
June 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10376

           Summary: Glaring hole in const system
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2013-06-16 04:36:52 PDT ---
DMD 2.063:

class C{ int[] x=[1,2,3]; }

void main(){
    auto c = new immutable(C)();
    auto d = new C();
    static assert(is(typeof(c.x[0])==immutable));
    assert(c.x[0]==1);
    d.x[0]=2;
    assert(c.x[0]==2);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10376



--- Comment #1 from timon.gehr@gmx.ch 2013-06-16 04:39:37 PDT ---
This could be fixed by having two versions of C.x, one in the writable and one in the non-writable data segment.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10376


Peter Alexander <peter.alexander.au@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au@gmail.co
                   |                            |m


--- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> 2013-06-16 07:27:41 PDT ---
Surely the bigger bug here is that they share the same array, regardless of mutability? I would expect each instance of C to default with a new array.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10376



--- Comment #3 from timon.gehr@gmx.ch 2013-06-16 10:49:40 PDT ---
(In reply to comment #2)
> Surely the bigger bug here is that they share the same array, regardless of mutability?

There is in fact an issue related to this:

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

If it is valid, then this can be treated as a duplicate, but the spec is silent about it. OTOH, the spec states that immutable memory does not change during its lifetime, legitimizing this report.

> I would expect each instance of C to default with a new array.

Currently, there is one static init block that is blitted over the class memory before the constructor is called. What you suggest would IMO be another valid way to resolve this issue.

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