How to break const
deadalnix
deadalnix at gmail.com
Wed Jun 20 08:17:47 PDT 2012
Le 20/06/2012 16:55, Timon Gehr a écrit :
>>> It works if implicit conversions from 'R delegate(A)' to
>>> 'R delegate(A) const' are allowed, as well as looking up an
>>> 'R delegate(A) in a const receiver object.
>>
>> What about conversion from/to immutable ?
>
> Simple application of transitivity. This part is the same for 1./2.
>
> 'R delegate(A)' and 'R delegate(A) const' are not convertible to
> 'R delegate(A) immutable', but 'R delegate(A) immutable' is
> convertible to 'R delegate(A)' and 'R delegate(A) const'.
>
> 'R delegate(A)' and 'R delegate(A) const' decay to
> 'R delegate(A) immutable' when stored in an immutable object.
>
I've gone through a similar reasoning. It does not work. Here are
implicit casts summed up :
mutable -> const
immutable -> const
immutable -> mutable
which implicitely imply immutable -> const
And then you add when storing in immutable object.
mutable -> immutable
const -> immutable
It means that you can store a delegate that have a mutable frame pointer
into an immutable object, which break transitivity.
More information about the Digitalmars-d
mailing list