With DMD, inout can be used to coerce away immutability as follows: int* foo(inout(int)* x)@safe{ inout(int)* screwUp(inout(int)*){ return x; } return screwUp((int*).init); } void main(){ immutable x = 123; static assert(is(typeof(*&x)==immutable)); assert(*&x==123); immutable(int)* y = &x; *foo(y)=456; assert(*&x==456); assert(x!=*&x); // (!) }
https://github.com/D-Programming-Language/dmd/pull/2455
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/988eae63db3be236428f7753dee0812ef6aed5ec fix Issue 10758 - Unsound type checking for inout
The patch misses to take into consideration inout member functions. Eg. the following function still manages to unsafely coerce its argument to mutable: int* foo(inout(int)* x)@safe{ struct S{ inout(int)* screwUp()inout{ return x; } } return S().screwUp(); }
(In reply to comment #3) > The patch misses to take into consideration inout member functions. Eg. the > following function still manages to unsafely coerce its argument to mutable: > > int* foo(inout(int)* x)@safe{ > struct S{ inout(int)* screwUp()inout{ return x; } } > return S().screwUp(); > } https://github.com/D-Programming-Language/dmd/pull/2487
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a61e407fa9fa7e20e8035f41d4c26569e06b5ed8 Additional fix issue 10758 for inout method of nested aggregate https://github.com/D-Programming-Language/dmd/commit/0542bbb77850e65a206b625970dc8b33ff6fe2fb Merge pull request #2487 from 9rnsr/fix_inout Additional fix issue 10758 for inout method of nested aggregate