Bug 15306 – Delegates with shared context can have unshared aliasing

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-09T12:12:00Z
Last change time
2016-10-03T10:25:55Z
Keywords
pull, safe
Assigned to
nobody
Creator
jakobovrum
See also
https://issues.dlang.org/show_bug.cgi?id=16335

Comments

Comment #0 by jakobovrum — 2015-11-09T12:12:03Z
void main() { int i = 42; // Correctly prevented for immutable context // auto dg = delegate void() immutable { auto inner = i; }; // Incorrectly allowed; context has unshared aliasing int* p = &i; auto dg = delegate int() shared { return *p; }; assert(dg() == i); } --- Also, there doesn't appear to be any inference of the context type qualifier, neither for function literals nor nested functions. Taking the address of a member function of an immutable/shared object doesn't seem to give the context type qualifier either.
Comment #1 by jakobovrum — 2015-11-09T12:12:53Z
(In reply to Jakob Ovrum from comment #0) > void main() > { > int i = 42; > > // Correctly prevented for immutable context > // auto dg = delegate void() immutable { auto inner = i; }; > > // Incorrectly allowed; context has unshared aliasing > int* p = &i; > auto dg = delegate int() shared { return *p; }; > assert(dg() == i); > } > > --- > > Also, there doesn't appear to be any inference of the context type > qualifier, neither for function literals nor nested functions. Taking the > address of a member function of an immutable/shared object doesn't seem to > give the context type qualifier either.
Comment #2 by dfj1esp02 — 2015-11-10T11:51:36Z
Looks like quite non-trivial feature and delegates don't provide much type safety anyway.
Comment #3 by bugzilla — 2016-08-27T08:40:37Z
Comment #4 by github-bugzilla — 2016-08-27T19:29:56Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/96136d6e4b1330650ca1fbf5afa57c2758ee18d3 fix Issue 15306 - Delegates with shared context can have unshared aliasing https://github.com/dlang/dmd/commit/fa9cea7a43fe8ccdd483fac11c3c1a194aab1336 Merge pull request #6093 from WalterBright/fix15306 fix Issue 15306 - Delegates with shared context can have unshared ali…
Comment #5 by github-bugzilla — 2016-10-01T11:48:37Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/96136d6e4b1330650ca1fbf5afa57c2758ee18d3 fix Issue 15306 - Delegates with shared context can have unshared aliasing https://github.com/dlang/dmd/commit/fa9cea7a43fe8ccdd483fac11c3c1a194aab1336 Merge pull request #6093 from WalterBright/fix15306
Comment #6 by dfj1esp02 — 2016-10-03T10:25:55Z
How about const qualifier? void f() { int i = 42; auto dg = delegate void() const { i=0; }; //ok? }