D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23639 - Casting to shared not allowed with -preview=nosharedaccess
Summary: Casting to shared not allowed with -preview=nosharedaccess
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 blocker
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2023-01-18 12:16 UTC by RazvanN
Modified: 2023-01-20 12:59 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description RazvanN 2023-01-18 12:16:27 UTC
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 RazvanN 2023-01-18 12:17:16 UTC
This is blocking the templatization of the _d_new_class druntime hook.
Comment 2 RazvanN 2023-01-18 12:48:42 UTC
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 Dlang Bot 2023-01-18 13:47:47 UTC
@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 Dlang Bot 2023-01-20 12:59:16 UTC
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