www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10376] New: Glaring hole in const system

reply d-bugmail puremagic.com writes:
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



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: -------
Jun 16 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10376




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: -------
Jun 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jun 16 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10376





 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: -------
Jun 16 2013