Why D const is annoying

Timon Gehr timon.gehr at gmx.ch
Sun Dec 11 13:04:30 PST 2011


On 12/11/2011 08:35 PM, Andrei Alexandrescu wrote:
> On 12/11/11 12:40 PM, Mafi wrote:
>> void f(ref const(int)* a, const(int)* b) {a = b; }
>> void main() {
>> immutable(int)* a;
>> auto b = (new int[](5)).ptr;
>> f(a, b);
>> //if this compiles I have just assigned a mutable pointer
>> //to an immutable one
>> }
>
> immutable(int)* does not convert to immutable(const)*.
>
> Andrei

I think you meant an lvalue of type immutable(int)* does not convert to 
ref const(int)*.
DMD currently allows it. http://d.puremagic.com/issues/show_bug.cgi?id=4251


More information about the Digitalmars-d mailing list