Comment #0 by komatsu.kazuki.op — 2024-08-17T15:39:00Z
References to shared variables can be obtained without atomic operations, but foreach statements that take references to array elements produce unexpected errors with -preview=nosharedaccess.
I have confirmed that all dmd compilers from version 2.093.1 to latest (and also in the current nightly where the last commit hash is 1d2e15e) have the same bug.
```d
void main()
{
//OK: We can get a reference of a shared variable.
{
void foo(ref shared(int) a) {}
shared int a;
foo(a);
}
//NG: Cannot get a reference to each element of an array on foreach-loop
{
shared(int)[] arr;
// Error: direct access to shared `__r2[__key3]` is not allowed, see `core.atomic`
foreach(ref e; arr) {}
}
}
```
Comment #1 by robert.schadek — 2024-12-13T19:36:51Z