www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23639] New: Casting to shared not allowed with

https://issues.dlang.org/show_bug.cgi?id=23639

          Issue ID: 23639
           Summary: Casting to shared not allowed with
                    -preview=nosharedaccess
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: razvan.nitu1305 gmail.com

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?

--
Jan 18 2023