digitalmars.D.bugs - [Issue 8288] New: immutable(char)** is not convertable to const(char)**
- d-bugmail puremagic.com (28/28) Jun 23 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8288
- d-bugmail puremagic.com (33/33) Jun 23 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8288
http://d.puremagic.com/issues/show_bug.cgi?id=8288 Summary: immutable(char)** is not convertable to const(char)** Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: admin dav1d.de --- Comment #0 from David <admin dav1d.de> 2012-06-23 04:00:05 PDT --- This Code: void foo(const(char)** arg) {} void main() { string yay = "fun"; auto yay_data = yay.ptr; foo(&yay_data); } Produces this Error: Error: function compileme406.foo (const(char)** arg) is not callable using argument types (immutable(char)**) Error: cannot implicitly convert expression (& yay_data) of type immutable(char)** to const(char)** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 23 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8288 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- Comment #1 from Kenji Hara <k.hara.pg 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: -------
Jun 23 2012