Bug 10758 – Unsound type checking for inout.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-04T16:01:00Z
Last change time
2014-09-14T15:06:38Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
timon.gehr
See also
https://issues.dlang.org/show_bug.cgi?id=10850

Comments

Comment #0 by timon.gehr — 2013-08-04T16:01:37Z
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); // (!) }
Comment #1 by k.hara.pg — 2013-08-07T23:16:26Z
Comment #2 by github-bugzilla — 2013-08-18T16:40:58Z
Comment #3 by timon.gehr — 2013-08-19T03:06:54Z
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(); }
Comment #4 by k.hara.pg — 2013-08-20T19:42:48Z
(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
Comment #5 by github-bugzilla — 2013-08-27T13:18:03Z
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