Bug 6823 – Shared Delegates Should Implicitly Cast to Nonshared

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-17T23:58:06Z
Last change time
2021-01-24T06:20:05Z
Assigned to
No Owner
Creator
Andrew Wiley

Comments

Comment #0 by debio264 — 2011-10-17T23:58:06Z
Code Example: synchronized class Thing { void doSomeWork(void delegate() work) { work(); } void work() {} } void main() { auto th = new Thing(); th.doSomeWork(&th.work); } This example won't compile because the type of `&th.work` is `void delegate() shared`, which will not implicitly convert to `void delegate()`. This type is probably correct - it's safe to share that delegate between threads, but since it's also safe to NOT share that delegate between threads, the delegate should implicitly cast to non-shared. This is a large problem for code using shared data because `void delegate() shared` does not parse as a type. The current workaround is to insert a cast to `void delegate()` at the call site.
Comment #1 by maxhaton — 2021-01-24T06:20:05Z
I'm not sure on the type conversion aspect but `void delegate() shared` has worked for years (at least < 2.060LD)