Bug 23639 – Casting to shared not allowed with -preview=nosharedaccess

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-18T12:16:27Z
Last change time
2023-01-20T12:59:16Z
Keywords
pull
Assigned to
No Owner
Creator
RazvanN

Comments

Comment #0 by razvan.nitu1305 — 2023-01-18T12:16:27Z
Consider the following code: class T {} shared(T) allocClassMem() { void *p; // assume p is allocated here return cast(shared(T))p; } This yields: Error: direct access to shared `cast(shared(T))p` is not allowed, see `core.atomic` How is one supposed to allocate shared memory if casting is not allowed?
Comment #1 by razvan.nitu1305 — 2023-01-18T12:17:16Z
This is blocking the templatization of the _d_new_class druntime hook.
Comment #2 by razvan.nitu1305 — 2023-01-18T12:48:42Z
Update, the problem is not the casting. Casting is fine. The problem is the fact that the result of the cast is a shared expression that is returned, therefore it needs to be synchronized.
Comment #3 by dlang-bot — 2023-01-18T13:47:47Z
@RazvanN7 created dlang/dmd pull request #14836 "Fix Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess" fixing this issue: - Fix Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess https://github.com/dlang/dmd/pull/14836
Comment #4 by dlang-bot — 2023-01-20T12:59:16Z
dlang/dmd pull request #14836 "Fix Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess" was merged into master: - a799c1b59ea617c0237f30ada65438a8a6d05657 by RazvanN7: Fix Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess https://github.com/dlang/dmd/pull/14836