Thread overview
core.atomic.atomicStore and structs
Mar 03, 2020
Saurabh Das
Mar 03, 2020
MoonlightSentinel
Mar 03, 2020
Saurabh Das
Mar 03, 2020
MoonlightSentinel
Mar 03, 2020
Saurabh Das
March 03, 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

March 03, 2020
On Tuesday, 3 March 2020 at 09:12:40 UTC, Saurabh Das wrote:
> Is this supposed to not work anymore? Or is this a bug?

That is a bug, see https://issues.dlang.org/show_bug.cgi?id=20629


March 03, 2020
On Tuesday, 3 March 2020 at 10:57:36 UTC, MoonlightSentinel wrote:
> On Tuesday, 3 March 2020 at 09:12:40 UTC, Saurabh Das wrote:
>> Is this supposed to not work anymore? Or is this a bug?
>
> That is a bug, see https://issues.dlang.org/show_bug.cgi?id=20629

Oh wow you fixed it already! Amazing!

Thanks MoonlightSentinel.

Saurabh

PS: Any chance this will make it into DMD 2.091.0?



March 03, 2020
On Tuesday, 3 March 2020 at 11:04:53 UTC, Saurabh Das wrote:
> PS: Any chance this will make it into DMD 2.091.0?

Yes, this fix will be in the upcoming release.
March 03, 2020
On Tuesday, 3 March 2020 at 11:35:35 UTC, MoonlightSentinel wrote:
> On Tuesday, 3 March 2020 at 11:04:53 UTC, Saurabh Das wrote:
>> PS: Any chance this will make it into DMD 2.091.0?
>
> Yes, this fix will be in the upcoming release.

Excellent.

Thank you so much! :)

Saurabh