Bug 17743 – Type system hole: escaping inout delegates

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-08-11T15:36:42Z
Last change time
2024-12-13T18:54:00Z
Keywords
safe
Assigned to
No Owner
Creator
timon.gehr
Moved to GitHub: dmd#17812 →

Comments

Comment #0 by timon.gehr — 2017-08-11T15:36:42Z
DMD v.2075.0: @safe: int a; immutable(int) b=2; inout(int)* delegate(inout(int)*) dg; inout(int)* prepare(inout(int)* x){ dg = y=>x; return x; } void main(){ prepare(&b); int* y=dg(&a); assert(&b is y); // passes. ouch. *y=3; assert(b is *&b); // fails! }
Comment #1 by schveiguy — 2017-08-14T13:32:14Z
This is why inout data is not allowed to be stored as a global (which essentially you have done). Basically, inout data should not be allowed to escape the function except via the parameters or return, where it is properly handled.
Comment #2 by dfj1esp02 — 2021-12-13T13:36:57Z
As I understand, it's due to decision that nested functions use inout qialifier of the outer function. Then an easy way to fix this is to disallow conversion of such nested function to inout-typed delegate.
Comment #3 by robert.schadek — 2024-12-13T18:54:00Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17812 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB