[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
Sun Jun 12 08:18:50 PDT 2011


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


yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, patch
                 CC|                            |yebblies at gmail.com


--- Comment #3 from yebblies <yebblies at gmail.com> 2011-06-12 08:14:13 PDT ---
https://github.com/D-Programming-Language/dmd/pull/115

When implicitly converting types with indirections, only allow the following
results:
> completely mutable
> completely non-mutable
> exactly one mutable indirection
> the same number of mutable indirections as before

eg.
> T*** => const(T***)   allowed, full const
> T*** => const(T**)*   allowed, tail const
> T*** => const(T*)**   not allowed
> T*** => const(T)***   not allowed
> T*** => T***          allowed, same number of mutable indirections
> immutable(T*)** => const(T*)** allowed, same number of mutable indirections
etc

This prevents (as far as I know) using implicit conversions to let a pointer to
mutable and a pointer to immutable point to the same place using const
conversions.

eg.
int** a = [new int].ptr;
const(int)*** b = &a;
*b = [new immutable(int)].ptr;

The same applies to other reference types.

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