core.atomic.atomicStore and structs

Saurabh Das saurabh.das at gmail.com
Tue Mar 3 09:12:40 UTC 2020


Hi,

Consider this code:

```
import core.atomic;

struct MyStruct
{
     uint a, b;
}
static assert(MyStruct.sizeof == ulong.sizeof);

void main()
{
     shared MyStruct ms1;

     MyStruct ms2 = atomicLoad(ms1);     // This is fine

     MyStruct ms3;
     cas(&ms1, ms2, ms3);                // This is also fine

     atomicStore(ms1, ms2);              // This gives a compile 
error
}
```

This used to work in DMD 2.088.1. It does not work in the latest 
DMD 2.091.0-beta.2. It gives a compile error like this:

```
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/internal/atomic.d(233): Error: template core.internal.atomic.atomicExchange cannot deduce function from argument types !(cast(MemoryOrder)5, false)(MyStruct*, MyStruct), candidates are:
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/internal/atomic.d(291):        atomicExchange(MemoryOrder order = MemoryOrder.seq, bool result = true, T)(T* dest, T value)
   with order = order,
        result = false,
        T = MyStruct
   whose parameters have the following constraints:
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   > is(T : ulong)
     or:
   > is(T == class)
     or:
   > is(T == interface)
     or:
   > is(T U : U*)
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Tip: not satisfied constraints are marked with >
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/atomic.d(127): Error: template instance core.internal.atomic.atomicStore!(cast(MemoryOrder)5, MyStruct) error instantiating
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/atomic.d(142):        instantiated from here: atomicStore!(cast(MemoryOrder)5, MyStruct, MyStruct)
atomic_test.d(18):        instantiated from here: 
atomicStore!(cast(MemoryOrder)5, MyStruct, MyStruct)
```

Is this supposed to not work anymore? Or is this a bug?

Thanks,
Saurabh



More information about the Digitalmars-d-learn mailing list