[Issue 4251] Hole in the const system: immutable values can be overwritten (const(T) is appendable to const(T)[])

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 16 12:17:07 PDT 2011


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



--- Comment #9 from Stewart Gordon <smjg at iname.com> 2011-06-16 12:12:23 PDT ---
(In reply to comment #5)
>>> immutable(T*)** => const(T*)** allowed, same number of mutable indirections

As it turns out, this is unsafe, as the following code shows:

----------
import std.stdio;

void main() {
    immutable(int) i = 42;
    immutable(int)* ip = &i;
    immutable(int)** ipp = &ip;
    const(int)** cpp = ipp;

    int m = 69;
    // the next statement makes ip point to a mutable value!
    *cpp = &m;

    writefln("%d", *ip);
    m = 105;
    writefln("%d", *ip);
}

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