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


Kenji Hara <k.hara...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Kenji Hara <k.hara...@gmail.com> 2012-06-23 21:42:07 PDT ---
This is design. The compiler rejects such conversion to keep const-correctness
will be broken.

See following test case.

----
void main()
{
    string yay = "fun";
    immutable(char)*  ip = yay.ptr;
    immutable(char)** ipp = &ip;

    // Implicit conversion from immutbale(char)** to const(char)** is
    // not allowed. But if this is allowed...?
    const(char)** cpp = ipp;

    char[] mstr = ['a', 'b', 'c'];
    char* mp = mstr.ptr;
    *cpp = mp;
        // You can rewrite a value of pointer to immutable data
        // as a value of pointer to mutable data!
    assert(cast(void*)ip is cast(void*)mp);
        // breaking const correctness!

    assert(*ip == 'a');
    mstr[0] = 'x';
    assert(*ip == 'x'); // immutable data is rewritten!!
}

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

Reply via email to