With 2.063, this code would work.
struct S { int* ptr; } // has mutable indirection
void main()
{
immutable S si = function () pure
{
S sm;
sm.ptr = new int;
*sm.ptr = 10;
return sm; // construct and return mutable object
}();
static assert(is(typeof(*si.ptr) == immutable int));
assert(*si.ptr == 10);
}
The local function would return an unique object, so it is implicitly
convertible to immutable.
Kenji Hara
2013/5/29 Jakob Ovrum <[email protected]>
> On Wednesday, 29 May 2013 at 12:40:39 UTC, Dicebot wrote:
>
>> Why something like this is not usable?
>> -----------------------
>> int tmp;
>> try
>> {
>> tmp = ...;
>> }
>> catch(..)
>> {
>> }
>> const(int) i = tmp;
>> -----------------------
>> Not really pretty but nothing crazy.
>>
>
> const(int) i = tmp; // fails when the type has mutable indirection.
>